TweakCode
Worked Systems lessons

Course 08 · Orientation

Worked Systems

Shortener, limiter, feed, chat

Four systems the public design canon keeps returning to, because each one needs a different block: a cached key lookup, a counter on the request path, fanout, and an ordered log behind live connections.

Start with URL Shortener

The course journey

Build one family of skills at a time

Each technique is three short lessons, and each one builds on the lesson before it. A lesson walks through one problem step by step, then hands it to you along with a few more to solve on your own.

  1. 01Start here

    URL Shortener

    The smallest full design: a key, a cache, and a code scheme with no collision checks.

    Preview
    1. Stage 1

      Base-62 Encoding of Unique IDs

    2. Stage 2

      Distributed ID Generation (Snowflake)

    3. Stage 3

      Lazy Expiry on the Read Path

  2. 02Pro

    Rate Limiter

    A tiny atomic counter in front of an expensive handler.

    1. Stage 1

      Token Bucket Rate Limiting

    2. Stage 2

      Layered Limits by IP and Account

    3. Stage 3

      Distributed Counters with Atomic Increments

    Preview
  3. 03Pro

    News Feed

    Fanout on write, with celebrities merged on read.

    1. Stage 1

      Fanout-on-Read (Pull Model)

    2. Stage 2

      Fanout-on-Write (Push Model)

    3. Stage 3

      Hybrid Fanout for Celebrities

    Preview
  4. 04Pro

    Chat

    A log for every conversation, and live connections for whoever is online.

    1. Stage 1

      Ordered Logs & Sync Cursors

    2. Stage 2

      Heartbeats & TTL Presence

    3. Stage 3

      Group Fanout with Pub/Sub & Read Cursors

    Preview