Playground Checkpoint
Design and build a real schema — no auto-grading, just a real attempt.
The Challenge
Eight chapters of real Redis, all converging on one real challenge: build GreenMart's actual flash-sale system, the way this whole Act argued it should be built — not a plain cache in front of a slow database, but the real toolkit.
Open the Playground and write real commands: reserve the last unit of a listing atomically, start a session that expires on its own, acquire a distributed lock around the checkout, rate-limit a shopper's requests, queue an order confirmation for later processing, and update a live leaderboard.
What Your Flash-Sale Cache Needs
- A stock counter for one listing, reserved using DECR (not a separate GET-then-SET) — so two simultaneous requests can never both believe they got the last unit.
- A session (a Hash with at least two fields) that expires on its own after a set number of seconds, using EXPIRE.
- A distributed lock around the checkout for one listing, acquired with SET ... NX EX — including a second attempt that should fail because the lock is already held.
- A rate limiter for one shopper using INCR, with EXPIRE set only on the first request in the window.
- An order confirmation queued with LPUSH and claimed with RPOP.
- A live leaderboard of top sellers today, updated with ZADD and read back in order with ZRANGE ... WITHSCORES.
Stuck? A Few Hints
- Reread the atomic-operations chapter's exact DECR and SET...NX EX examples — this checkpoint reuses the same shape, just against your own keys.
- For the rate limiter, INCR first — only call EXPIRE when INCR's own result comes back as 1.
- SADD's return value already tells you if something was new — you won't need it here, but the same "check the return value, don't assume" habit applies to DECR and SET...NX too.
Ready to Build It?
Opens the Playground, right in your browser — nothing to install.
Every command should return a real reply — OK, an integer, a value, or (nil). The second SET ... NX EX attempt on an already-held lock should come back (nil), not an error — that (nil) is the checkpoint working correctly, not a sign something went wrong.
Before You Move On
Six chapters of Redis, in one script: an atomic counter, an expiring session, a distributed lock, a rate limiter, a queue, and a leaderboard. None of it was "caching a slow database" in the sense that started this Act — that's exactly the mistake this Act's Goal set out to correct. The next Act moves past a single machine's memory entirely, into a database built to run across a fleet of them from day one.
