Resource · Guide or article
Design a key-value cache to save the results of the most recent web server queries
Focuses on one component: a key-value cache that holds results for recent search queries in front of a search backend. It fits candidates who want to practice LRU eviction and cache sharding inside a system design answer, and it assumes you know hash tables and linked lists.
Reviewed
Open the original: Design a key-value cache to save the results of the most recent web server queries (opens the original site in a new tab)Practice this topicOpens the practice interviewer in System design mode; choose a question there.
Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
A worked system design exercise from “The System Design Primer”. Steps: Outline use cases and constraints; Create a high level design; Design core components; Scale the design.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Guide
What it covers
- Assumes 10 billion queries a month at 270 bytes per entry, which would mean 2.7 TB a month if every query were unique and stored, and 4,000 requests per second.
- Walks through the hit and miss paths, including query parsing and calls to a reverse index service and a document service.
- Implements an LRU cache in Python with a doubly linked list plus a hash table for lookups.
- Uses a time to live so entries refresh when pages change, appear, disappear or change rank.
- Compares three ways to spread the cache across machines and favors sharding, with consistent hashing.
How to use it
PrepKit study advice, not a claim made by the source.
Code the LRU cache from scratch with constant-time get and set, then compare it with the page's version. Be ready to say which of the three cluster layouts you would choose and what each one costs in hit rate or memory.
Scope and limitations
Narrower than the other exercises: it designs the cache, not the search system behind it. Figures come from the exercise's own assumptions, and the design is one option among several. The Python sample has small syntax errors and elided methods, and the consistent hashing link points to a section marked under development.
Access and format
README on GitHub in the donnemartin/system-design-primer repository by Donne Martin, licensed CC BY 4.0. English, free to read online.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: ae9bbd7b02d9
Evidence behind this overview
- solutions/system_design/query_cache/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.