Read Redis first, fall back to Cloud SQL, and have a plan for stale data
Say a phone goes on offer on a Flipkart-style store, and its product page is opened 10,000 times in a few minutes. The details and price are the same for everyone. Without a cache, the database answers the same question 10,000 times.
The problem
Cloud SQL is the source of truth for product details and price. It is good at that, but every read costs CPU, connections and time. When a few popular products get most of the traffic, the database spends its effort repeating itself, and real work like placing orders waits in the same queue.
The CDN does not solve this one. It is great for files that are the same for everyone, such as product images. Price and stock are data that the app builds and changes, so they belong in a cache next to the app, not at the edge.
The solution: cache-aside with Memorystore
Memorystore is Google Cloud's managed Redis.…