inflearn logo

Commerce Cache Design: Handling Traffic Spikes Across Local, Distributed, and Database Layers

We fix product and event APIs that buckle under traffic at sale launch with local L1 and remote L2 caches, stampede prevention, invalidation, and a kill switch—and prove with before-and-after numbers how much bandwidth, latency, and database load drop under the same traffic.

2 learners are taking this course

Level Intermediate

Course period Unlimited

Node.js
Node.js
PostgreSQL
PostgreSQL
Redis
Redis
k6
k6
cache
cache
Node.js
Node.js
PostgreSQL
PostgreSQL
Redis
Redis
k6
k6
cache
cache

What you will gain after the course

  • Identify large keys and hot keys, create a table of key size × request count (in bytes), and quantify the impact of cache changes by comparing before and after under the same load and over the same time window.

  • Design a two-tier cache with local L1 and remote L2, justify its size and TTL, and explain why the remote cache breaks down under bandwidth limits.

  • Prevent stampedes with single-flight, distributed locks, probabilistic early refresh, TTL jitter, and negative caching; use event invalidation and version keys to treat the consistency window as a policy.

  • Serve rankings using sorted sets and design dual writes, recovery, circuit breakers, kill switches, and response contracts.

Under the same load, failures dropped from 3,567 to 0, and remote cache traffic fell from 200.7 MB to 4.6 MB. The final outcome of this course is fixing failing commerce APIs firsthand and proving the results with before-and-after metrics.

We fix product and event APIs that buckle under sale-launch traffic using local L1 + remote L2 + stampede prevention + invalidation + a kill switch, then prove with before-and-after numbers how much bandwidth, latency, and DB load are reduced under the same load.

This isn’t a course that teaches Redis commands or data structures one by one. In a Docker lab environment, we recreate the opening-day traffic surge for the Season-Off Festa at Loop Market, a fictional sports and outdoor specialty store run by a small development team. We then measure and fix, one by one, the reasons things can still fall apart even with a cache in place: bandwidth consumed by large responses, hot keys, stampedes, consistency windows, eviction policy conflicts, noisy neighbors, and expensive sections. Every figure is measured firsthand in the lab, and every lesson follows the same sequence: follow along → check the results → deliberately break something.

By the end of this course

  • Identify large keys and hot keys, then create a table using key size × request count (in bytes).

  • Report the impact of cache changes numerically by comparing before and after under the same load and over the same time window.

  • Design a two-tier cache with local L1 + remote L2, and determine the size and TTL based on evidence.

  • Prevent stampedes with single-flight, distributed locks, probabilistic early refresh, TTL jitter, and negative caching.

  • Use event-based invalidation and versioned keys to reduce the consistency window, and write a policy document for each data type.

  • Serve ordered data such as rankings using sorted sets, and design dual writes, recovery, and circuit breaking.

  • Measure eviction-policy conflicts and noisy-neighbor effects to build a case for isolating shared caches into dedicated instances.

  • Define a kill switch for disabling only the expensive sections, along with the response contract.

Recommended for people like these

  • Commerce backend developers who deal with cache and database outages during every sale or event.

  • For those who have tried Redis cache-aside but aren’t sure what to do next (bandwidth, stampedes, and invalidation)

  • A development lead who needs to report the impact of cache changes in numbers

Curriculum (9 sections · 32 lessons · about 194 minutes)

  • Section 0. Final Goal Demo — Preview the finished result

  • Section 1. Lab Environment and Baseline — Set up the lab environment, the Loopmarket API and data, the load generator and dashboard, baseline: the database collapses without a cache

  • Section 2. The Pitfalls of Remote Caching — Bandwidth — Add a remote cache with cache-aside, large responses consume bandwidth, measure key size distribution, how to measure and compare the same window before and after, compression and sharding aren’t fundamental solutions

  • Section 3. Local L1 + Remote L2 Two-Tier Cache — Using a local cache as L1, choosing the L1 size and TTL, multiple instances and the consistency window, comparing the same window before and after L1, pitfalls of L1

  • Section 4. Hot Keys and Stampedes — Finding hot keys, reproducing cache stampedes, locks and single-flight, probabilistic early refresh, TTL jitter, and negative caching

  • Section 5. Invalidation and consistency windows — Event-based invalidation, version keys, and using consistency windows as a policy

  • Section 6. DB and Ordered Data — The app cannot control the DB buffer cache, serving rankings with sorted sets, circuit breakers and fallbacks

  • Section 7. Operations — Isolation, Kill Switches, and Observability — deciding when to separate into a dedicated cluster, measuring noisy neighbors, kill switches and response contracts, cache observability dashboards

  • Section 8. Capstone — Capstone: Turn everything on and prove it under the same load, then review the complete checklist and wrap up

Hands-on Environment

With a single Docker Compose file, you can launch the LoopMarket product and event API (Node.js, two instances), a Redis-compatible server (Valkey for the exercises) with primary and replica nodes, PostgreSQL, a k6 load generator, and Prometheus and Grafana. The replica node’s outbound bandwidth limit is reproduced using tc. Feature flags let you enable and disable L1, stampede prevention, invalidation, and the kill switch without rebuilding, and 32 scenario scripts let you reproduce every result from the course exactly. Exercise materials (ZIP) are included.

Prerequisites

  • Experience building an API with either Spring or Node.js.

  • Redis Basics (GET/SET/TTL)

  • Basic use of Docker and the terminal

What This Course Does Not Cover

  • Redis Installation and Command Basics

  • Internal implementation of cluster sharding

  • Cloud Managed Service Console Setup

Notice

The lecture narration was produced using an AI-generated voice. All data is simulated for educational purposes, and the numbers may vary depending on the execution environment.

Recommended for
these people

Who is this course right for?

  • A commerce backend developer who deals with cache and database outages during every sale or event.

  • For those who have tried cache-aside but find bandwidth, stampedes, and invalidation daunting

  • A development lead who needs to quantify the impact of cache changes.

Need to know before starting?

  • Experience building an API using either Spring or Node.js.

  • Redis Basics (GET/SET/TTL)

  • Basic Docker and Terminal Usage

Hello
This is dorian05202988

Career Verified

A data craftsman with over 20 years of experience in databases and IT. As a DBA and manager of a DB Platform team, I work with database platforms and specialize in MySQL, PostgreSQL, Oracle, MongoDB, SQL tuning, AWS, Terraform, and Python. Drawing on experience in the gaming, finance, and IT services industries, I explain database and cloud architecture. I have published 『Oracle Practical Tuning: Learning SQL Patterns』 and 『Oracle Pro*C Practical Project Guide』, and have presented on serverless architectures, database selection, and multi-database strategies at AWS Summit 2018 and 2019 and DataYa Nolja 2020. Recently, I have been working on slow-query analysis and tuning recommendations using Bedrock LLM, automated DB specification sizing, and query workflows through a DB metadata MCP server and Slack bot. I explain database automation for developers and AI applications for non-developers through hands-on exercises tailored to the audience and objectives of each course. Rather than applying AI suggestions as-is, I teach a decision-making framework that verifies result equivalence, execution plans, and observability conditions, and defers action when the supporting evidence is insufficient. Company operational data and credentials are not included in the course materials.

More

Curriculum

All

32 lectures ∙ (3hr 13min)

Course Materials:

Lecture resources
Published: 
Last updated: 

Reviews

Not enough reviews.
Please write a valuable review that helps everyone!

dorian05202988's other courses

Check out other courses by the instructor!

Similar courses

Explore other courses in the same field!

Limited time deal

$52,800.00

41%

$70.40