AITeky Learn

AiTeky Original Interactive Learning & Practice Intermediate

Key-value stores: fast lookups, expiry, counters and caching

Build a small in-memory key-value store in Python, give keys a time to live, use counters, sets and sorted sets for real jobs, write an LRU cache and measure its hit rate, then size a cache for a busy product page.

A key-value store is the simplest database there is: you give it a key, such as user:42:name, and it gives back the value. Because it keeps data in memory and does almost nothing else, it answers in a fraction of a millisecond. That makes it the standard place for sessions, counters, queues, leaderboards and caches in front of a slower database. Redis is the best-known example.

In this course you build the pieces yourself in Python so you can see what each command does and why it is fast. The commands are modelled on the ones Redis has, but this is a teaching version: check the product's own documentation for exact syntax and limits. All the traffic and prices are made up.

  • Learn lessons explain one idea at a time and let you run it.
  • Industry ready lessons decide and justify, and end with interview questions.

You need basic Python: functions, dictionaries and loops.

Locked. Sign up free

Learn

Understand each idea with everyday examples. No coding background needed.

  1. 01 30 min Free sample 🔒 AiTeky Pass Keys, values and time to live Build a tiny key-value store with set, get, delete and incr, see why a dictionary lookup does the same work for ten keys or a million, give keys a time to live so old data cleans itself up, and use it for a login session.
  2. 02 35 min 🔒 AiTeky Pass Counters, sets and leaderboards: more than strings Use a counter with an expiry to limit how often a user may try something, a set to count unique visitors, a sorted set for a live leaderboard and a list as a queue of jobs, each built from a few lines of Python so you see why these shapes exist.
  3. 03 35 min 🔒 AiTeky Pass Caching: cache-aside, hit rate and the LRU rule Put a cache in front of a slow database with the cache-aside pattern, measure the hit rate on realistic uneven traffic, write a least-recently-used cache that evicts the right entry, and see how the hit rate grows (and stops growing) as the cache gets bigger.

Industry ready

Real problems from real jobs, and the questions interviewers ask about them.

  1. 04 40 min 🔒 AiTeky Pass On the job: sizing a cache and choosing a time to live A product page gets 300 views a second at the sale peak and the database can take 60. Simulate the traffic and price changes, measure database load and wrong prices shown for four cache settings, pick one, and write the recommendation for the engineering lead.

We use essential cookies to run the site. With your permission we also set one anonymous ID to count unique visitors, and analytics cookies to see which pages help learners. Cookie notice

Join AiTeky Learn. It's free.

Create a free account to track your progress, save items for later and get study suggestions.

Sign up free Log in