Skip to content
LeetQuant
QD10 System Design and Code Review

QD10 · System Design and Code Review · Lesson 1 of 5

System Design Method

A repeatable order for a system design interview (requirements, API, data model, high-level design, bottlenecks, trade-offs) and the back-of-envelope estimates that size each part, worked through for a market-data store.

18 min

What the interviewer is scoring

A system design round is open-ended on purpose. "Design a service that stores and serves historical market data" has no single right answer, so the interviewer scores how you get to an answer: whether you pin down what is being built before drawing boxes, whether your numbers are in the right order of magnitude, whether you find the part that will break first, and whether you can say what you gave up for what you gained.

The objective of this lesson is a fixed sequence you can run on any prompt, with estimates attached to each step. Candidates who skip straight to "we'll use Kafka and a database" lose the round even when the boxes are reasonable, because nothing they said was tied to a requirement or a number.

The six steps

StepOutputTypical time in a 45-minute round
1. RequirementsFunctional list, non-functional targets (latency, throughput, durability, availability), what is out of scope5–8 min
2. EstimatesRequest rate, data volume per day and per year, bandwidth, peak-to-average ratio3–5 min
3. APIThe handful of calls clients make, with arguments and return shapes3–5 min
4. Data modelEntities, keys, how data is partitioned and indexed5 min
5. High-level designComponents and the path a write and a read take through them10 min
6. Bottlenecks and trade-offsThe component that saturates first, how it fails, what you would change at 10× scale10 min

The order matters because each step constrains the next. The access pattern from the API decides the partition key; the volume estimate decides whether one machine is enough; the latency target decides whether a cache or an in-memory design is needed at all.

Step 1: requirements, said out loud

Ask questions that change the design, not questions for their own sake:

  • Who are the clients and what do they do most? Researchers scanning years of data for many symbols (throughput, sequential reads) are a different system from a trading engine that needs the latest quote (latency, point reads).
  • What are the numbers? Symbols, message rate, history depth, concurrent users.
  • What must never happen? Lost data, a wrong price served, stale data served as fresh. This sets durability and consistency.
  • What is out of scope? Say it explicitly: "I will not design the exchange feed handler; I assume normalised messages arrive on a stream."

Write the non-functional targets as numbers: "p99 read latency under 100 ms for a one-day, one-symbol query", "no acknowledged write is lost", "99.9% monthly availability for reads". A number can be designed against; "fast and reliable" cannot.

Step 2: estimates

Back-of-envelope estimates use round numbers and powers of ten. The constants worth memorising:

QuantityValue
Seconds in a day86,400≈10586{,}400 \approx 10^5
Seconds in a US equity session (6.5 h)23,40023{,}400
Trading days per year252252
1 KB, 1 MB, 1 GB, 1 TB103,106,109,101210^3, 10^6, 10^9, 10^{12} bytes (decimal is fine for estimates)
Main-memory readabout 100 ns
Same-datacentre round tripabout 0.5 ms
Sequential read from SSDon the order of 1 GB/s

Always state the peak, not only the average. Market data is bursty: the open and close and news events can run one to two orders of magnitude above the session average, and a system sized for the average falls over exactly when it matters.

Worked example

sizing a tick store

You are asked to store every normalised order-book message for US equities. Assume 1 billion messages per day, all arriving during the 6.5-hour session, each stored in a compact binary record of 40 bytes. Assume bursts run at about 20× the session average, columnar compression gives 4×, and storage is replicated 3 times. Estimate the average and peak message rate, ingest bandwidth, and storage per day and per year.

Show solution

Rates. The session is 6.5×3600=23,4006.5 \times 3600 = 23{,}400 s, so the average rate is

10923,400≈42,700 messages/s.\frac{10^9}{23{,}400} \approx 42{,}700 \text{ messages/s}.

At 20× the peak is about 855,000855{,}000 messages/s; round up and design for 1 million messages/s.

Bandwidth. Average: 42,700×40≈1.742{,}700 \times 40 \approx 1.7 MB/s. Peak: 106×40=4010^6 \times 40 = 40 MB/s, which is 320320 Mbit/s. That fits comfortably on one 10 GbE link and one machine's write path, so ingest does not need to be sharded for bandwidth; it may still be replicated for availability.

Storage. Raw per day: 109×40=4×101010^9 \times 40 = 4 \times 10^{10} bytes =40= 40 GB. Per year: 40×252=10,08040 \times 252 = 10{,}080 GB ≈10\approx 10 TB raw. Compressed 4×: about 2.52.5 TB per year. Replicated 3×: about 7.67.6 TB of disk per year of history.

What the numbers tell you. Ten years is roughly 76 TB replicated: too much for one machine's disks but small for object storage, so the design is "append the day's data to a log during the session, write compressed columnar files partitioned by date and symbol after the close, serve reads from those files". The hard part is not storage volume; it is the read path for wide queries, which the next steps address.

Steps 3 and 4: API and data model

Keep the API to the calls that matter and make the arguments reveal the access pattern:

get_ticks(symbol, start_ts, end_ts)            -> stream of messages
get_bars(symbols[], start_date, end_date, freq) -> table (symbol, ts, o, h, l, c, v)
get_snapshot(symbol, ts)                        -> order book at ts

Read the API back as a statement about the data model. get_ticks scans one symbol over a time range, so data should be physically sorted by (symbol, timestamp) within a partition. get_bars over many symbols and years is a large sequential scan, so a columnar layout (read only the columns asked for) and precomputed bars pay off. get_snapshot needs either a replay from the previous snapshot or periodic stored snapshots, which is a classic space-for-time trade.

A sensible partition key is (date, symbol): a day's ingest writes one set of partitions, a query for one symbol over a month touches about 21 partitions, and a backfill or correction for one day rewrites only that day.

Steps 5 and 6: design, then break it

Draw the write path (feed → append-only log → end-of-day compaction into columnar files → catalogue of partitions) and the read path (client → query service → catalogue → files, with a cache for hot bars). Then go looking for the bottleneck, in this order:

  1. The component that sees peak load first. Here, the ingest log at 1M messages/s during the open.
  2. The component with the largest fan-out. A "10 years of 1-minute bars for 5,000 symbols" query reads millions of rows from thousands of partitions.
  3. The component with no redundancy. A single catalogue database is a single point of failure for every read.

For each, say what happens under failure and what you would change at 10× scale. That discussion is where most of the marks are.

Worked example

is a bar store a big-data problem?

A researcher wants 1-minute bars for 5,000 symbols over 10 years. Each bar is stored as six 8-byte fields (timestamp, open, high, low, close, volume), with the symbol implied by the partition. There are 390 one-minute bars in a session. How large is the full dataset, and what does that imply for the design?

Show solution

Bars: 5,000×390×252×10=4,914,000,000≈4.9×1095{,}000 \times 390 \times 252 \times 10 = 4{,}914{,}000{,}000 \approx 4.9 \times 10^9.

Bytes: 4.9×109×48≈2.36×10114.9 \times 10^9 \times 48 \approx 2.36 \times 10^{11}, about 236 GB uncompressed.

One symbol-day is 390×48=18,720390 \times 48 = 18{,}720 bytes, under 19 KB. Two conclusions follow:

  • The whole bar history fits on a single large SSD and could be scanned at around 1 GB/s in a few minutes. It is not a distributed-computing problem; one well-organised machine, or a columnar file store, serves it.
  • Partitioning bars by (date, symbol) would create 5,000×2,520=12.65{,}000 \times 2{,}520 = 12.6 million files of 19 KB each, which is terrible for any file system or object store. For bars, partition coarser, for example one file per symbol per year or one file per day holding all symbols. The right partition size depends on the data, and the estimate is what tells you.

Saying "236 GB, so it fits on one box" in an interview is worth more than any amount of distributed architecture, because it shows you sized the problem before solving it.

Knowledge check

A service receives 200 million requests per day, evenly spread over 24 hours, with peaks at 5 times the average. Roughly what peak request rate should you design for?

Knowledge check

Your design's main API call is 'get all ticks for one symbol between two timestamps'. Which physical layout serves it best?

Knowledge check

Which of these is a non-functional requirement stated in a form you can design against?

Key takeaways

  • Run the same sequence every time: requirements, estimates, API, data model, high-level design, bottlenecks and trade-offs.
  • Turn every non-functional requirement into a number with a percentile and a load.
  • Estimate with round numbers and always size for the peak; market data bursts well above its average.
  • Let the API's access pattern choose the partition key and sort order.
  • Use estimates to decide what is hard: 40 GB a day of ticks and 236 GB of bars are storage problems a single well-designed system handles; the interesting work is the read path and failure handling.

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).