9 steps · ~45 min · intermediate · free

Cache-aside with Redis

Nimbus Books now runs the same expensive catalog query on every request. Add Redis beside PostgreSQL, implement cache-aside in the application, prove the hit path, then stop Redis and inspect stale data.

Run this architecture yourself

Start the lab locally with real Docker containers.

Torollo runs locally on desktop with Docker.

npx torollo start

Run the command in a terminal on your computer, then open Cache-aside with Redis in Torollo.

Docker requiredlocal onlyMIT licensed

Execution plan

9 graded steps against one system as you build it.

Baseline

Build the slow catalog path and measure it.

01-04
  1. Reopen the store

    Start a web container for the Nimbus Books catalog.

    • check: container "web" is running
  2. The catalog

    Create the PostgreSQL catalog and seed its books.

    • check: container "db" is running
    • check: table "books" exists in "db"
  3. Least privilege, day one

    Allow only the web server to reach PostgreSQL on port 5432.

    • check: web → db is reachable on :5432
  4. The 1500-millisecond problem

    Serve the catalog with an intentional 1500 ms database delay.

    • check: GET :80/ on "web" contains "Nimbus Books"
    • check: GET :80/ on "web" contains "The Pragmatic Programmer"

Cache

Add Redis, fill it and prove the hit path.

05-07
  1. Enter Redis

    Add Redis and limit its network access to the web server.

    • check: container "cache" is running
    • check: web → cache is reachable on :6379
    • check: cache → db is blocked on :5432
  2. Cache-aside

    Read from Redis first, then fill the cache after a miss.

    • check: GET :80/ on "web" contains "Nimbus Books"
    • check: key "cache:books" exists in "cache"
  3. Prove the hit

    Inspect the Redis key and compare the hit and miss paths.

    • check: key "stats:hits" exists in "cache"
    • check: GET :80/ on "web" contains "served from cache"

Failure

Stop the cache and observe stale data.

08-09
  1. The cache goes dark

    Stop Redis and confirm the store falls back to PostgreSQL.

    • check: key "stats:drills" exists in "cache"
    • check: container "cache" is running
  2. The stale catalog

    Change the catalog and observe how cached data becomes stale.

    • check: GET :80/ on "web" contains "Phoenix"
    • check: GET :80/ on "web" contains "served from cache"

Run locally

Start the roadmap on your machine

Torollo runs the lab in local Docker containers. The roadmap and its validators ship with the MIT-licensed app.

Inspect the source on GitHub

Before you start

  • Docker installed and running
  • A Torollo project created and open on the canvas (start from an empty one)
  • Comfortable running basic commands in a Linux terminal
  • Having played "Deploy a resilient three-tier app" helps, but this story stands on its own