Guides
Step-by-step guides with diagrams and code on computer science fundamentals and system design. Read one, then practise the topic with real questions.
- Design a rate limiter: Where it lives, the algorithms and their trade-offs, working code, Redis at scale, and the numbers.
- Design a URL shortener: Short codes, 301 vs 302, collisions, caching, abuse, and counting clicks without slowing the redirect.
- Caching strategies: Where caches live, cache-aside and the other patterns, eviction, invalidation races, and how to survive stampedes.
- Consistent hashing: Why hash mod N breaks when servers change, how the ring and virtual nodes fix it, with code and alternatives.
- How database indexes work: B-trees, composite index order, covering indexes, reading EXPLAIN, and why the database ignores your index.
- Transaction isolation levels: Dirty reads to write skew, the four standard levels versus what PostgreSQL and MySQL really do, and how to fix each problem.
- TLS and HTTPS: How the TLS 1.3 and 1.2 handshakes work message by message, why forward secrecy and certificates matter, what resumption and 0-RTT cost, and the mistakes that cause outages.
- What happens when you type a URL: DNS, TCP, TLS, HTTP and rendering in order, with a hand-built 29-byte DNS query, curl timings for each phase, and the standard ways to cut each round trip.
- The CAP theorem and consistency models: What CAP really says, a CP versus AP partition experiment, quorums (R + W > N), the spectrum from linearizable to eventual, and PACELC.
- Load balancing: Layer 4 versus layer 7, a simulation of random, round robin, least connections and power of two choices, health checks, draining and sticky sessions.
- Message queues and delivery guarantees: At-most-once, at-least-once and exactly-once in practice: the transactional outbox, idempotent consumers, visibility timeouts and dead-letter queues, run on PostgreSQL.
- Design a news feed: Fan-out on write versus read, the celebrity problem and the hybrid, Redis timelines with measured memory, keyset versus OFFSET pagination timed on PostgreSQL, ranking, deletes and privacy.
- Design a web crawler: The URL frontier with per-host politeness (code in four languages), URL normalisation, a measured Bloom filter, robots.txt, near-duplicate detection, spider traps tested on a local site, and freshness.
- Persistent identifiers and link rot: Why a URL fails as a name, how a DOI is built and resolved, normalising and checking identifiers (measured: ISBN-13 and ORCID catch typos, DOIs cannot), why a 301 breaks updates in a real browser, content negotiation, and rules for designing your own identifiers.
- Design a DOI resolver: A read-heavy redirect service that must outlive the sites it points to: the lookup path in Python and Go, a tested TTL cache and a Zipf hit-rate simulation, why sharding by prefix makes hot shards, versioned writes, tombstones, a safe link checker and content negotiation.
- Designing a multi-tenant system: Silo, bridge and pool tenancy compared with measurements on PostgreSQL: Row-Level Security, composite foreign keys, a schema and role per tenant, the pooled-connection leak, per-tenant timeouts, migrations and dumps across 1,000 tenants, tenant resolution and noisy neighbours.
- Concurrency: races, deadlocks and the event loop: Threads, event loops and goroutines compared; the lost update and the deadlock as animations you can step through; what the fixes cost, measured in Go and Python; and the one rule of an event loop.
- Designing a REST API: Resources and URLs, methods and their guarantees, status codes and errors, and three tested risks: a retried POST that creates two orders, OFFSET paging that repeats items, and conditional requests with ETags.
- Authentication and sessions: Storing passwords (measured hashing costs), sessions and cookie flags, JWTs, XSS and CSRF, OAuth 2.0 with PKCE and OpenID Connect, one-time codes and passkeys, and the authorisation mistakes behind most breaches.
- Distributed transactions: two-phase commit and sagas: Why one business operation across several databases is hard, two-phase commit (and how it blocks), sagas with compensations and their missing isolation, and idempotent steps with an outbox, all run on PostgreSQL and small Python services.
- Observability: logs, metrics and traces: What each of the three signals answers, why averages hide slow requests and percentiles cannot be averaged, label cardinality, log cost, trace propagation and sampling, and alerting on SLO burn rates, with a two-service example in Python.
- Replication, partitioning and sharding: What each of the three tools scales, replication lag and read-your-writes, what an asynchronous failover loses, partition pruning, shard-key choice, hot shards and resharding, run on PostgreSQL and in Python.
- Resilience patterns: timeouts, retries and circuit breakers: How a slow dependency spreads, and the tools that contain it: timeouts and deadlines, retries with backoff, jitter and budgets, circuit breakers, bulkheads, backpressure and load shedding, with measured experiments and two step-by-step animations.
- Operating systems: processes, threads, virtual memory and scheduling: Processes against threads, context switches, round-robin scheduling, virtual memory, page faults, copy-on-write, page replacement and thrashing, with measurements on Linux and two step-by-step animations.
- DNS, HTTP/2, HTTP/3 and CDNs: How a name is resolved and cached, what a new connection costs, how HTTP/2 multiplexing and HTTP/3 over QUIC remove head-of-line blocking, and how a CDN's hit ratio, cache keys and headers decide its value.
- Search and full-text indexing: The inverted index, analysis, BM25 ranking, posting list compression, segments and merging, sharded search, keeping an index in step with the database, and when Postgres full-text search is enough.
- The memory hierarchy and Big-O in practice: Cache lines and locality, why the same O(n) loop can be 18 times slower, row against column order, struct layouts, linked lists, branch prediction and when the constant factor beats the exponent, with measured C experiments.
- Consensus: Raft, leader election and log replication: How a group of machines agrees on a log despite crashes: quorums, Raft's terms, randomised elections, replication and the commit rule, partitions and what survives them, with a simulation, fault injection and two step-by-step animations.
- Storage engines: B-trees and LSM trees: How B-trees update pages in place and LSM trees append, flush and compact, with measured write, read and space amplification, Bloom filters, compaction strategies and when to choose which.
- Microservices, API gateways and service meshes: What splitting into services really costs in latency and availability, how to draw boundaries, synchronous against asynchronous communication, the API gateway and BFF, service discovery and the service mesh, and the strangler fig migration.
- Web application security: injection, XSS, CSRF and secrets: Injection, cross-site scripting, CSRF, broken access control, path traversal, SSRF, unsafe deserialisation and leaked secrets, each shown with the vulnerable code, the attack and the fix, plus supply chain, headers and response.
- Event sourcing and CQRS: Storing facts instead of state: the event store, optimistic concurrency, replay and snapshots, read models and projectors, eventual consistency, event design and upcasting, and when it is not worth it.
- Containers and Kubernetes: What a container really is (namespaces, cgroups and image layers, measured), and how Kubernetes keeps desired state: the control plane, scheduling by requests, rolling updates and probes, and autoscaling.
- Git internals and CI/CD pipelines: Git as a content-addressed object store (hashes, packfiles, bisect, rebase), branching strategies, continuous integration and delivery, and how canary, blue/green and rolling releases limit the damage of a bad release.
- Garbage collection and memory management: Reachability, reference counting against tracing, generational collection, what heap headroom and collector choice cost (measured in Java, Go and Python), leaks in managed languages and sizing a heap in a container.
- Compilers, interpreters and language runtimes: From source text to running code: lexing, parsing, optimisation, bytecode machines and just-in-time compilation, with a tree walker, a bytecode VM and compiled code measured side by side.
- Time-series and high-write systems: Designing for a steady stream of small writes: batching and COPY, delta-of-delta and XOR compression, expiring data by dropping partitions, label cardinality, rollups and why percentiles cannot be averaged.
- Design a chat system: A worked design with numbers: persistent connections, per-conversation sequence numbers for ordering, idempotent delivery, fan-out on write against on read, presence, offline sync and very large groups.
- How Python works: Names as labels on objects, mutability and the mutable default argument, the data model behind operators and loops, generators (1.4 KB against 409 MB), closures and late binding, reference counting and the cycle collector, __slots__, and measured costs.
- Python performance and concurrency: Profiling first, what the interpreter costs per item, NumPy against loops, the GIL measured with threads and processes, process pool overhead, asyncio and blocking calls, and how to choose.
- Python classes, inheritance and typing: Attribute lookup, the MRO and super(), properties and descriptors, dataclasses and what they cost, abstract base classes, Protocols, and what type hints do and do not guarantee at runtime.
- Python decorators, generators and async: Decorators built from closures, functools.wraps and lru_cache (and the method pitfall), lazy generator pipelines, coroutines and the event loop, gather against sequential await, cancellation, TaskGroup and never blocking the loop.
- Python errors, resources and testing: The exception hierarchy and try/else/finally, chaining with from, EAFP against LBYL (measured), context managers and ExitStack, and unittest with mocks: patching where a name is used, spec, test independence, flaky tests and what coverage means.
- Python packaging, environments and imports: How an import finds and runs a module, sys.path and shadowing, relative and circular imports, what a virtual environment really is, pyproject.toml and editable installs, version specifiers, lock files and dependency security.
- Python for data and web work: containers, pandas, WSGI and ASGI: Which built-in container fits the job and what it costs, how pandas gets its speed and where it surprises you, and how a web request reaches your code through WSGI or ASGI. With measured results: dict lookups, deque against list, records against columns, vectorised against looped pandas, and 20 concurrent requests on sync, threaded and async servers.
- Advanced React: re-renders, memoization, refs, data fetching and what React 19 changed: How React renders and re-renders, a triage ladder from measuring through structure, caching and the React Compiler to transitions and virtualization, identity and keys, Context against split contexts and stores, stale closures, refs, layout and portals, data fetching (waterfalls and out-of-order responses explained by arithmetic you can check, and how to measure your own) and error handling, with what React 19.3 changed.
- Idempotency and exactly-once effects: keys, retries and deduplication: Why a timeout makes retries, and so duplicates, unavoidable; naturally idempotent designs; idempotency keys and the race in check-then-act (465 extra charges against none); foreign calls and recovery points; the outbox and the inbox; and what keeping the keys costs.
- Capacity estimation: load, storage, bandwidth and memory on the back of an envelope: The constants worth memorising, what one small machine really does (measured), a seven-step method with Littles law, worked examples for a URL shortener, photo sharing and chat, how long data takes to move, and the mistakes that make estimates wrong by ten.
- Choosing a database: access patterns, trade-offs and measured costs: How to choose a database from the questions you will ask of it: the main families (relational, document, key-value, wide-column, graph, search, columnar, time series) and their trade-offs, measured comparisons of documents against tables, queries with and without an index, graph hops, full-text search and row against column layout, one system of record with derived stores, and a checklist for design discussions.
- TCP in practice: connections, latency, timeouts and what breaks in production: What TCP does and does not promise, what a connection costs (handshakes, TLS, slow start, windows), the 40 ms stall of Nagle's algorithm with delayed ACKs, TIME_WAIT and port exhaustion, the accept backlog, half-open connections, keepalive and timeouts, with measurements from loopback experiments and a symptom table for diagnosing production problems.
- Go runtime in practice: goroutines, channels, the scheduler, memory and garbage collection: How the Go runtime behaves and what it costs, with measurements: goroutine memory and start-up cost, the G, M and P scheduler and preemption, channels against mutexes and atomics, data races and the memory model, goroutine leaks and context cancellation with a worker pool, escape analysis and allocation costs, GOGC and GOMEMLIMIT, and the language behaviours that surprise people.
- Learned perceptual metrics: LPIPS, perceptual losses, style transfer and DeepDream: Why PSNR and SSIM mislead (with numbers you can reproduce) and how deep features fix it: the LPIPS distance and the BAPPS human judgements behind it, using LPIPS and pyiqa and choosing between metrics, feature (perceptual) losses, neural style transfer and the Gram matrix as a distribution match, DeepDream as gradient ascent on the image, the perception-distortion trade-off, and the traps of learned metrics.
- Which image filter should I use? A decision guide: Start from what is wrong with the picture (noise, impulse specks, softness, uneven light) and pick the filter: box, Gaussian, median, unsharp mask, Laplacian or gradient. How to size the kernel, why sizes scale with resolution, what separability saves, how to treat the border, and the common mistakes.
- Point versus neighbourhood processing: what each can and cannot do: The two families of image operations side by side: lookup tables for point operations, sliding windows for neighbourhood ones. What each can and cannot do, why a nonlinear tone curve and a filter do not commute, the operations that live in both worlds, and the default order for a pipeline: denoise, tone, sharpen.
- Filtering in space and in frequency: one operation, two views: Convolution as multiplication of spectra and the impulse as a constant. The sum of a kernel is its gain at zero frequency, highpass, bandreject and bandpass kernels built from one lowpass, why a wide Gaussian has a narrow spectrum, aliasing and filtering before shrinking, and when to compute in the frequency domain.
- Image enhancement recipes: shading, contrast, sharpening and noise: Five worked recipes with symptom, steps, parameters and failure modes: uneven illumination (divide by a Gaussian estimate), dark or low-contrast images, soft photographs (unsharp masking and its halos), noisy medical images (Laplacian masked by a smoothed gradient), and specks on a scan (median). Two runnable code samples.
- Go slices, arrays and maps: headers, growth, aliasing and memory retention: How slices really work and why they surprise people: the three-word header, length and capacity, how append grows (with measured capacities), aliasing through shared arrays and function arguments, preallocation (12 allocations against 1), memory retention by sub-slices and deleted pointers, and the rules for maps and range.
- Go context: cancellation, deadlines, values and causes: How to use the context package correctly: the four methods, the tree of derived contexts, every constructor including WithCancelCause, WithoutCancel and AfterFunc, why you must call cancel, how to honour cancellation in loops and blocking calls, Canceled against DeadlineExceeded, request values, HTTP servers, retry budgets, and the common mistakes.
- Git: undoing mistakes with the reflog, reset, revert, rebase and recovery: A practical guide to getting out of trouble in Git: the three areas (working tree, index, repository), what each reset mode touches, the reflog as a recovery tool with its limits, reset against revert, amend and fixup with autosquash, interactive rebase, cherry-pick, merge conflicts (zdiff3, rerere), stash, force-with-lease, and finding what changed.
- Git submodules, subtrees, worktrees, sparse and partial clones, and LFS: What each Git tool for sharing code and handling big repositories really does, with real command output: submodules (gitlinks, .gitmodules, detached HEAD, update, push order, removal, pitfalls), subtrees, worktrees, shallow and partial clones, sparse checkout, Git LFS, and a decision chart that includes the option of a package manager.
- Protocols: HTTP, SOAP, REST, gRPC, GraphQL, WebSockets and messaging: The protocols a working engineer meets, compared with the same six questions: HTTP and REST, SOAP and the WS-* family, JSON-RPC and gRPC with protobuf on the wire, GraphQL, WebSockets, server-sent events and long polling, webhooks, AMQP, MQTT and STOMP, and SMTP, FTP, SFTP and SSH, with real bytes, an error-vocabulary table across protocols, ports, versioning, tracing and a decision chart.
- How a query planner works: plans, estimates and why they go wrong: Reading an execution plan and fixing a bad one: the four access paths and three join algorithms a planner chooses between, where cost numbers come from, how row counts are estimated and why the independence assumption and hidden expressions wreck them, join ordering and the search space, what the executor does with a plan, and an ordered ladder for diagnosis - with every plan, row count and timing produced by a PostgreSQL 16 instance you can reproduce from the appendix.
- The JavaScript event loop: tasks, microtasks and why order surprises people: One thread, a call stack, a task queue and a microtask queue: how setTimeout, promises, async/await and queueMicrotask are ordered, why a long synchronous loop freezes a page, and how to yield without breaking things - with every output in this guide produced by running it in Node.
- Closures and `this` in JavaScript: scope, binding rules and the classic traps: How lexical scope and closures keep variables alive, the loop-with-var trap, and the four rules that decide what `this` is (new, explicit, method call, default), why arrow functions ignore them, and how to lose and recover `this` - with every output produced by running the code in Node.
- Prototypes and classes in JavaScript: how objects inherit and what `class` really is: The prototype chain and property lookup, how new, Object.create and class relate, what class fields, private # members and super do, why mutating shared prototype data bites, and when composition beats inheritance - with every output produced by running the code in Node.
- JavaScript modules: ES modules, CommonJS and what bundlers actually do: The difference between import/export (ES modules) and require/module.exports (CommonJS): live bindings against copied values, static against dynamic loading, how Node decides which one a file is, top-level await, dynamic import(), tree shaking, circular imports and what a bundler adds - with outputs produced by running the code in Node 22.
- async/await in C#: what the compiler does, deadlocks and the rules that keep it safe: How an async method becomes a state machine, what Task and ValueTask are, why .Result and .Wait() can deadlock, when ConfigureAwait matters, how to run work concurrently with Task.WhenAll, cancellation with CancellationToken, and the async void trap - with the rules stated plainly and the cases that depend on the runtime flagged.
- LINQ in C#: deferred execution, multiple enumeration and IQueryable: Why a LINQ query runs when you enumerate it and not where you write it, how that causes repeated work and surprising results, the difference between IEnumerable (runs in memory) and IQueryable (translated to SQL), which operators buffer or stream, and the habits that avoid the usual bugs.
- Dependency injection in .NET: lifetimes, captive dependencies and scopes: What the built-in container does, the three lifetimes (transient, scoped, singleton) and when each is right, the captive-dependency bug where a long-lived service holds a short-lived one, how scopes map to requests, injecting factories and IOptions, and how to test with it.
- Entity Framework Core in practice: change tracking, N+1 queries and loading related data: How a DbContext tracks entities and turns changes into SQL on SaveChanges, when to use AsNoTracking, the N+1 problem and the four ways to load related data (Include, split queries, projection, explicit loading), concurrency tokens, migrations and the habits that keep queries predictable.
- Modern C# data modelling: records, immutability and nullable reference types: What a record gives you (value equality, with-expressions, deconstruction), record class against record struct against class, init-only and required members, what nullable reference types really check and what they do not, and how pattern matching ties them together.
- Authentication and sessions: passwords, cookies, tokens and OAuth without the folklore: How to store passwords, what a session is and how session cookies are protected, when a signed token (JWT) is a good idea and when it is not, how OAuth 2.0 and OpenID Connect divide the work between authorization and login, multi-factor authentication and passkeys, and the mistakes that show up in most breach reports.
- Web application attacks and their defences: injection, XSS, CSRF, SSRF and broken access control: How the five most common web vulnerability classes work, with the one defence for each that actually fixes the cause (parameterized queries, contextual output encoding, SameSite and tokens, outbound allowlists, server-side authorization checks), plus the defence-in-depth layers (CSP, headers, least privilege) and a short review checklist.
- Design a notification system: push, email and SMS at scale: A case study in fan-out and reliability: requirements and back-of-envelope numbers, an architecture with a request API, per-channel queues and workers, templates and user preferences, how to get at-least-once delivery without sending twice, retries with backoff, rate limits and priority, and what to measure.
- Design search autocomplete (typeahead): tries, top-k and latency: A case study in serving suggestions within 100 ms: requirements and numbers, a trie with cached top-k results at each node, how the data pipeline builds it from query logs, caching and sharding, handling freshness and trending queries, and the client-side details (debounce, prefix cache) that matter as much as the server.
- Design a file storage and sync service (Dropbox-style): A case study in large files and many devices: splitting files into content-addressed blocks, a metadata service separate from block storage, delta sync and deduplication, change notification to other devices, conflict handling, sharing, and the numbers that show why the block store, not the database, is the big cost.
- Design a payment system: idempotency, ledgers and reconciliation: A case study in correctness over speed: the payment flow with a payment service provider, idempotency keys, a double-entry ledger, state machines for a payment, handling timeouts and unknown outcomes, webhooks, reconciliation against the provider's reports, and why you never store card numbers yourself.
- Design a metrics and monitoring system: time series at scale: A case study in write-heavy time-series data: what is collected and how (push or pull), ingestion through a queue, a time-series store with compression, downsampling and retention, an alert evaluator that avoids flapping, cardinality as the main cost driver, and dashboards that query the store efficiently.
- Design a ticket booking system: seats, holds and contention: A case study in correctness under contention: modelling events, seats and orders, why double-selling is the central risk, temporary holds with expiry, database locking and constraints that make a double sale impossible, handling the flash-crowd moment with a waiting room, payments that fail, and what can be cached safely.