Skip to content
About
Main content
Bytes at Rest

Core Data Structures

How do we choose a data structure when the real cost is set by the hardware, not by Big-O?

Who this mechanism is for: a developer who writes code, has seen arrays, hash maps and trees in a algorithms course, and knows basic SQL, but has never asked what a data structure costs on a real disk, , CPU cache or multi-core server. You do not need any database knowledge. Every technical term is explained the first time it appears, and again in the glossary at the end. You do not need to remember any other mechanism: whatever idea we need, we explain it here.

The story we will follow

Arjun is a backend engineer at Parcelo, a small company that tracks parcels for online shops. Every time a parcel is scanned (at a warehouse, on a truck, at a depot, at a doorstep) Parcelo stores a scan event: (tracking_id, timestamp, depot, status, weight). Customers ask "where is my parcel?". Shops run reports such as "how many parcels reached Pune last week?". The system is growing from 50 million events to 5 billion.

Lena is the tech lead. She asks one kind of question again and again: "What does this cost on the real machine?" She never accepts "it is O(log n)" as an answer. Scan events arrive from many ingest threads, are held in memory first, and are then written to files on SSD and to cloud object storage. Queries come from a web API and from nightly report jobs.

Parcelo has one rule written on the wall:

Over this mechanism, Arjun meets seven problems, one at the start of each article. Each problem looks like a bug: a table that is too big, a job that suddenly takes ten times longer, a server that gets slower when we add threads. Each one is actually a consequence of what a data structure promises and what it costs. At the end of each article we go back to Arjun and solve the problem with the article's mechanisms.

This is the main idea of this mechanism:

How this mechanism is organized

After that: a summary, hands-on labs, interview questions and a glossary.

One request: do not skip the arithmetic. This mechanism derives many small formulas (page size divided by row size, memory divided by transfer size). The derivations are the content. The structures themselves are only the examples.

What do I do, and what does each option cost?

Can I see it myself?

Can I reason about it under questioning?

Trade-offs

The tensions this mechanism takes a position on. Each recurs across mechanisms.

Show all 9 trade-offs
Recurring principles

Ideas this mechanism meets that keep coming back, mechanism after mechanism.

Show all 14 principles