Menu

1 / 4

Cache-Aside with Memorystore: Serve the Same Product Page Without Asking the Database Every Time

DEV Community: redis·Vishwa·about 5 hours ago
#sEoaoIpU
#devtoredis#devto#dev#redis#product
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.