{
  "docVersion": 1,
  "id": "template-url-shortener-at-scale",
  "name": "URL shortener at scale",
  "purpose": "Snowflake IDs mint slugs without coordination; reads flow CDN → cache (with negative caching) → hash-picked shard; clicks stream to analytics.",
  "nodes": {
    "user": {
      "type": "user",
      "label": "Visitor",
      "x": 20,
      "y": 240,
      "runtime": "GET /x7Ab9"
    },
    "cdn": {
      "type": "cdn",
      "label": "CDN Edge",
      "x": 280,
      "y": 240,
      "runtime": "302s cached · 80% never reach us"
    },
    "api": {
      "type": "server",
      "label": "Redirect Service",
      "x": 540,
      "y": 240,
      "runtime": "300µs budget",
      "color": "blue",
      "patterns": [
        "stateless",
        "autoscale"
      ]
    },
    "cache": {
      "type": "cache",
      "label": "Slug Cache",
      "x": 800,
      "y": 110,
      "runtime": "slug→url · 404s cached too",
      "notes": "Negative caching is the unsung hero: unknown slugs store their miss for 60s, so scanners fight the cache, not the shards."
    },
    "db": {
      "type": "database",
      "label": "Slug Store",
      "x": 1060,
      "y": 110,
      "runtime": "hash(slug) → shard",
      "patterns": [
        "sharded",
        "replicated"
      ]
    },
    "creator": {
      "type": "browser",
      "label": "Creator",
      "x": 20,
      "y": 480,
      "runtime": "shorten a long URL"
    },
    "createapi": {
      "type": "server",
      "label": "Create Service",
      "x": 540,
      "y": 480,
      "runtime": "mint + write"
    },
    "idgen": {
      "type": "server",
      "label": "ID Generator",
      "x": 800,
      "y": 480,
      "runtime": "snowflake: time|node|seq",
      "notes": "K-sorted IDs mean new slugs cluster in the same shard region — friendly to storage, zero coordination between nodes."
    },
    "analytics": {
      "type": "stream",
      "label": "Click Stream",
      "x": 1060,
      "y": 480,
      "runtime": "fire-and-forget"
    },
    "warehouse": {
      "type": "warehouse",
      "label": "Analytics",
      "x": 1320,
      "y": 480,
      "runtime": "counts · referrers · geo"
    }
  },
  "edges": {
    "e1": {
      "from": "user",
      "to": "cdn",
      "fromSide": "right",
      "toSide": "left",
      "label": "GET /x7Ab9",
      "animated": true
    },
    "e2": {
      "from": "cdn",
      "to": "api",
      "fromSide": "right",
      "toSide": "left",
      "label": "edge miss only",
      "animated": true
    },
    "e3": {
      "from": "api",
      "to": "cache",
      "fromSide": "right",
      "toSide": "left",
      "label": "lookup",
      "animated": true,
      "patterns": [
        "cache-aside"
      ]
    },
    "e4": {
      "from": "cache",
      "to": "db",
      "fromSide": "right",
      "toSide": "left",
      "label": "miss → shard read"
    },
    "e5": {
      "from": "api",
      "to": "analytics",
      "fromSide": "bottom",
      "toSide": "left",
      "label": "click event",
      "style": "dashed"
    },
    "e6": {
      "from": "creator",
      "to": "createapi",
      "fromSide": "right",
      "toSide": "left",
      "label": "POST /shorten"
    },
    "e7": {
      "from": "createapi",
      "to": "idgen",
      "fromSide": "right",
      "toSide": "left",
      "label": "next id"
    },
    "e8": {
      "from": "createapi",
      "to": "db",
      "fromSide": "top",
      "toSide": "bottom",
      "label": "write slug",
      "patterns": [
        "timeout"
      ]
    },
    "e9": {
      "from": "analytics",
      "to": "warehouse",
      "fromSide": "right",
      "toSide": "left",
      "style": "dashed",
      "patterns": [
        "batch"
      ]
    }
  },
  "boxes": {
    "b1": {
      "x": 760,
      "y": 20,
      "w": 490,
      "h": 280,
      "label": "read path — microseconds, cache-shaped",
      "color": "blue",
      "opacity": 0.04
    }
  },
  "texts": {
    "t1": {
      "x": 20,
      "y": 380,
      "text": "why negative caching matters:\nwithout it, every random slug a bot tries\nis a guaranteed cache miss AND a DB read —\nthe attack costs you more than the attacker",
      "color": "amber",
      "size": 12
    }
  },
  "meta": {
    "createdAt": "2026-07-13T09:00:00.000Z",
    "modifiedAt": "2026-07-13T09:00:00.000Z"
  }
}