Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Labs

Each lab takes one setting from a board and lets you change it. Move the control and watch the numbers update. Labs run in your browser, and nothing you enter leaves the page.

95labs
17tracks

System Design 19

Caching Free

The slate next to the stove

Most orders are for three favourites. How big does the slate need to be before a bigger one stops helping?

5eviction policies
10questions at the counter
1–6lines the slate holds
Concurrency Free

One wala, many kettles

Sixteen customers, one wala. If the wala stops standing at each kettle, how much sooner is everyone served?

736 → 121 ms16 orders, watched then juggled
384 msthe floor: 64 orders × 6 ms of work
1–4walas, the stall's cores
Queueing Free with an account

The order slip rail

The kitchen is 95% busy. How much longer do you wait than at 50%?

99×analytic wait at 99% busy
150×the board's simulated wait at 99%
50–99%how busy you can run the kitchen
Sharding With a plan

Splitting the ledger

Names are mostly A–D. You split A–M / N–Z. What happens?

3shard keys to try
2–6books on the shelf
70names arriving
Rate limiting With a plan

The bouncer at the door

The limit is 5 a minute. How many can one client land in a two-second span?

4ways to count a limit
10requests in the seam burst
5/minthe board's own rule
Replication With a plan

The copy clerks

You pay your tab at stall A and walk to stall B. What do they say you owe?

3ways to copy a book
14moments in the evening
1–6moments the clerks run behind
Network partitions With a plan

The cut phone line

The line between the branches is cut. What does the far clerk say to the customer in front of them?

3answers to one cut
2–9moments the line stays cut
0conflicts, if you refuse
Multi-region writes With a plan

Two kitchens, two cities

Two cities changed the same order a moment apart. Which change survives, and what did it cost to be sure?

37 msround trip, Virginia to Oregon
322 of 1,000wrong changes kept, west clock 50 ms behind
0wrong changes kept if you wait, or keep both
Idempotency With a plan

Charged twice

The reply never arrived. Did the money move, and what should the client do?

3answers to a lost reply
12payments, one evening
0–60%of messages the network eats
Consensus With a plan

Who holds the pen

The room splits in two. Both halves think they are in charge. Who is allowed to write?

5clerks, one pen
3rules for holding it
0diverging writes, with a fence
Distributed transactions With a plan

The two ledgers must agree

One transfer, two books, and a crash that lands between them. Where does the money end up?

3ways to move money twice
7moments a crash can land
1protocol that blocks
Choosing a datastore With a plan

The right book for the job

Fourteen real queries, six datastores. Which one answers yours without a second system?

6stores to try
14queries, fixed
0stores that win every row
Consistency With a plan

The ledger everyone reads

The same answer is correct under one promise and a violation under another. Which promise did you make?

4promises to a reader
20moments, one evening
0levels that are free
Writing to two systems With a plan

The write that happened twice

Every sale goes in the register and must also reach the warehouse. The app crashes now and then. Which design lets the two disagree?

2directions a dual write can disagree
0sales the outbox leaves on one side only
361slips resent at 10 crashes in 1,000
Consistent hashing With a plan

The ring

The ring rehomes only 1/N of the keys when a server dies. So why does everyone run two hundred virtual nodes per server?

67% to 6%load spread, 1 to 200 points
765 vs 7,513keys moved, ring against hash % N
1server inherits the hole, at one point each
Fan-out With a plan

Thirty stalls on one order

Every stall is slow one time in a hundred. An order that waits on a hundred stalls is slow how often?

1% → 63%one stall late, and 100-stall orders late
26% → 0.30%30 stalls, before and after hedging
+1 in 100extra calls a hedge costs at 1% slow
Counting a crowd Free

Counting the crowd

A hundred thousand different customers, and a tally board of 12 KB. How far off is its count?

12 KB16,384 tallies, whatever the crowd
0.81%the promised miss: 1.04 ÷ √16,384
8 MBan exact list of a million ids
Many buyers, one item With a plan

The last vada

Ten vadas left and a crowd reaching at once. How does the stall sell exactly ten, and what does making sure cost?

2 → 110phantom vadas with no guard, from 2 to 12 buyers per vada
5 per vadawhere checking the count again starts losing to the lock
250 a secondwhat one line hands over, whatever the crowd
Syncing only what changed With a plan

The tree that knows

You saved one file in a 50,000-file repo. How few hashes can the server read to find it, and when does the trick stop paying?

4.0 KB vs 3.2 MBone saved file: the walk against the whole list
15×hashes read, 1,000 edits scattered against in one folder
15.7%of the repo edited, scattered, before the list wins

How Computers Work 10

Memory hierarchy With a plan

The memory hierarchy

Same data, same O(n), four access patterns. Why is one of them 31 times slower?

4ways to walk the same data
31×scan vs pointer chase at 64 MB
4–200cycles, L1 to RAM
I/O Free

The interrupt storm

The device taps the CPU on every event. What happens when it taps a million times a second?

233k/swhere taking every tap peaks
0serviced at a million a second
500kthe hybrid still finishes there
Cache lines With a plan

Cache line life

You asked for four bytes. Sixty-four arrived. Who paid for the other sixty, and who else wanted them?

16×the traffic, same reads, stride 16
6.25%of each line used, at the floor
11×slower while two counters share a line
Floating point With a plan

Inside a float

Your program stores 0.1. What is actually in those 64 bits?

55decimal places in real 0.1
5.55e-17how far 0.1 + 0.2 misses
2^53where integers go missing
Files and storage With a plan

The fsync interval

Your write returned and the power cut a moment later. Is the record on the disk?

0 vs 7,777records lost at one crash, every record vs never
200 → 200,000records a second, every record to never
9.9×faster fsyncing every 10 instead of every 1
Parallel speedup With a plan

The parallel ceiling

Ninety-five percent of the job splits across cores. How much faster can it possibly finish?

20×ceiling at 95% parallel
24%of each core used, at 64
10cores before it gets slower
Virtual memory With a plan

The working set

The program needs twelve pages at once. What happens when it gets eleven frames?

32% → 87%time spent working, 11 frames vs 12
14×more page faults one frame short
+2.3 pointsfrom doubling memory past the working set
Whose turn is it With a plan

The time slice

Three long jobs are running when you press a key. How long until the keypress gets the CPU?

800 → 0.05 mskeypress wait, first come vs demote the hogs
2.9 → 500 mskeypress wait, 1 ms turns vs 200 ms
4.3% vs 0.03%CPU lost to swaps, 1 ms vs 200 ms turns
Thread pools With a plan

The thread pool

How many workers should a pool have, and why does the answer flip when the tasks mostly wait?

4,851finished a second, 10 workers on 10 cores
51 msslowest one in a hundred at 64 workers, up from 19
8×more finished at 64 workers when tasks mostly wait
Lock contention With a plan

The one key

Thirty-two hands share one key. The room is no slower than with two, so where did the extra hands go?

52.8% to 97%of each hand's time spent waiting, one key, 2 hands to 32
8.6×sixteen keys against one, at 32 hands
999 vs 1,000jobs a second, 64 hands on a 1 ms hold against one hand

AI 10

Tokenization With a plan

Tokens and embeddings

One sentence, one tokenizer, a vocabulary you can grow. How many tokens does it cost?

44 → 10tokens, same sentence
425merges, learned in-module
62tokens for 23 characters of another script
LLM inference With a plan

The batch size dial

One GPU, one chat, cores 99% idle. How many more chats fit before anything gets slower?

1.07operations per byte, against a ridge of 150
134chats before the cache fills the card
0.7%of the cores busy serving one chat
LLM sampling With a plan

The temperature dial

The model has read 'The weather today is'. How often does it say something other than sunny?

0.549of the drum misses sunny at T = 1
0.993sunny's share at T = 0.1, nearly greedy
671of 1,000 draws miss sunny at T = 2
Classifiers With a plan

The decision threshold

The filter has scored every email. How sure must it be before one goes to the spam folder?

100% to 56%precision, bar at 0.90 then 0.20
0 to 267false alarms per 1,000 good emails, same move
60% to 4%precision at 0.50, spam 1 in 4 then 1 in 100
Mixture of experts With a plan

Many experts, one router

Doubling the experts doubles what the model knows and costs nothing per token. So what does it cost?

47B → 13Bknown against computed, at Mixtral's width
0gigabytes saved by any of it
28%of a batch dropped by a collapsed gate
Agent loops With a plan

The loop cap

The returns desk's loop keeps asking the model until it answers. How many passes before it hands the customer to a person?

8 of 100answered by the loop at a cap of 1 pass
94 to 96answered, cap 8 then cap 20
$1,611 to $2,285a day at a million conversations, same move
RAG With a plan

The chunk size

The returns desk cuts its policy into pieces and hands the model the best few. How big should a piece be, and how many should go in?

0 of 7answers arrive whole at 10-word pieces, 3 in the window
4 of 7arrive whole at 25 words, 2 pieces, for 67 tokens
533 tokensto get all 7 at 200-word pieces, 95% not the answer
Training Free with an account

The learning rate

Every step of training walks the dials downhill. How far should each step go?

29 to 8steps to a loss under 0.01, rate 0.05 then 0.2
8.8 x 10^8loss at step 10 at rate 0.5, up from 33
2.26loss after 200 steps at 0.001, still crawling
Cheap model first, big model on doubt With a plan

The cascade threshold

Every request goes to the small model first. How sure must it be before its answer goes out?

94wrong answers in 1,000 get out at the lesson's -1.0 threshold
$0.97per 1,000 requests at -1.0, against $3.00 always-frontier
68wrong answers still out at both 0.50 and 0.80
A small correction beside frozen weights With a plan

The LoRA rank

Fine-tuning a 7B model with LoRA trains a small correction beside the frozen weights. How big should the correction be?

4.19 milliontrainable numbers at rank 8 on q and v, 0.060% of 7B
14.07 vs 112 GBmemory to train at rank 8, against a full fine-tune
+0.9quality-proxy points from rank 16 to 256, for 16x the numbers

DSA 7

Hashing With a plan

O(1) yaad

A hash map answers in one step, on average. What is the worst case, and when does it start to matter?

276keys, one fixed list
11 vs 3deepest peg, bad hash against good
153probes for the worst lookup at 99% full
Sorting With a plan

Sorting aur searching

Merge sort is O(n log n) and insertion sort is O(n squared). On the list you actually have, which does less work?

5 x 5sorts, input shapes
6.2xO(n squared) beating O(n log n)
35items before n log n wins
Big-O Free

How cost grows

A million items. O(n log n) finishes in a blink. How long does O(n²) take?

7rungs on the ladder
10¹²O(n²) operations at n = 1,000,000
6orders of magnitude on the slider
Intractability With a plan

The cliff at n = 11

Ten cities, and you can check every possible route. Eleven, and you cannot. So what do you ship for the eleventh?

181,440tours at n = 10, the last n that finishes
+18.4%the greedy tour's excess at n = 9
1%of n = 12's orders reached before the cap
Dynamic programming With a plan

The DP table

The same recursion runs three ways. Which one solves ways(3) fifty-five times, and which solves it once?

465calls to climb 12 stairs
55×ways(3) re-solved, vs once
0calls the table makes
Grab the biggest coin first With a plan

The greedy bet

Grabbing the biggest coin that fits gives the fewest coins with 1, 5, 10 and 25. Does it with any coins?

0 of 99amounts greedy gets wrong with 1, 5, 10, 25
3 vs 2coins for 6 with 1, 3, 4: greedy's 4 + 1 + 1 against 3 + 3
24 of 99amounts greedy gets wrong with 1, 3, 4
Keeping the chains short With a plan

The short chains

Every find walks a chain of houses up to the root. In the worst order, how long can that chain get, and what keeps it short?

31 hopsthe tallest chain after 31 cables with no habit
5 = log₂ 32the most union by size allows, even on its worst log
52 → 30find steps with path halving, paid for with 45 writes against 31

Mind Blown 6

Game Theory 6

DevOps 6

Load balancing With a plan

The load balancer

Every algorithm looks identical on the benchmark. Which one is still standing when two requests in a hundred cost sixty times the rest?

2 vs 8backends read, ask-two vs least
7.4s → 2.9sp99 wait, round robin to ask-two
55requests stranded on a dead backend
Firewalls With a plan

The two gates

Your packet passed both gates on the way in. Does the answer get back out?

1 vs 2rules for the same conversation
4gates one conversation passes
1024–65535the range that decides if it hangs
Autoscaling With a plan

The autoscaler lag

Your traffic goes up eightfold in three minutes and the HPA is working perfectly. Who still gets an error?

77%of a launch dropped on two pods
60%of the peak fleet's bill, for the HPA
15–120show long a new pod takes to serve
Backups With a plan

The restore drill

A backup every night, and someone drops the main table at 11:59 pm. What is the cheapest way to lose under a minute of writes instead of a day?

1 day → 28.8 sdata lost, nightly photos, then with the logbook
$28 → $34.72a month, the price of that logbook
15 min–1 dayhow often the database is photographed
Booking quay space With a plan

The berth plan

Each ship books quay space before it docks, and the harbour master trusts the booking. How much should a ship book?

33%of the hour's work squeezed when ships book 100m against a 500m tide
12 of 24ships left at anchor when every ship books 1000m
6.0 coresbooked and idle on average, even at the accurate 500m booking
Cheap servers that can be taken back With a plan

The spot share

Spot is 63.6% cheaper than on-demand, and it can be taken back. How much of the fleet should run on it?

$1,471.68 → $535.09ten m7i.xlarge servers for a month, all on-demand against all spot
63.6%the cheapest spot share at a = 0.5, $1,173.65 with spares
0.318the bite below which all spot is cheapest

Finance 6

Debt With a plan

The minimum payment

You owe 5,000 at 24% a year. What does paying 100, 110 or 250 a month actually buy you?

neverat 100 a month, the interest
122 monthsat 110, and 13,320 paid
26 monthsat 250, and 6,449 paid
Diversification With a plan

One cloud, many rivers

Each river swings 20% a year and shares some weather. Own a hundred: how much does your water still swing?

12.17%swing with 10 rivers at correlation 0.3
10.95%the floor, 20% x sqrt(0.3)
7%average flow at every setting
Options With a plan

The drought right

A right to buy one barrel of water at 100 in a year, when water costs 100 today. What is it worth, and what makes it worth more?

7.97at 20% volatility, strike 100, one year
15.85at 40%, same strike
0change to the payoff at expiry
Leverage With a plan

The borrowed bucket

Borrow two buckets for every one you own and pour all three into a market averaging 7% a year. Do you end up with more water?

1.75xwhere long-run growth peaks at 20% volatility
-4%long-run growth at 4x
0%of 1x paths sold out
Settlement With a plan

The netting window

Three banks send each other 48 payments in a day. Settle each the moment it is made, or pay only the difference at 17:00?

85%less water moved, netted once at 17:00
4,782promised and unpaid at 17:00
0exposed under gross settlement
Reconciliation With a plan

The nightly match

Card payouts reach the bank days late, and two payments never arrive. How long should an entry wait for its twin before someone is told?

60false alarms in a month at 0 days, payouts up to 4 days late
0false alarms at 3 days
4 daysthe missing payment hides at 3 days

Networking 5

Data Systems 4

Database Internals 4

How Things Work 4

Security 3

From Scratch 2

Personal Development 1

Philosophy 1

Psychology 1