Unique-ID-Generator-Design-diagram.excalidraw

==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==

Unique ID Generator — System Architecture Diagram

Text Elements

Service A ^svc-a-label Service B ^svc-b-label Service C ^svc-c-label getNextId() ^getnext-label ID Generator Service ^id-gen-label Snowflake-style 64-bit ID ^snowflake-title 1 bit sign ^bit-sign 41 bits timestamp ^bit-ts 5 bits datacenter ^bit-dc 5 bits machine ^bit-machine 12 bits sequence ^bit-seq Zookeeper / etcd ^zk-label machine ID assignment ^zk-arrow-label Downstream DB ^db-label monotonically sortable IDs ^db-arrow-label Alternatives: UUID (128-bit, no ordering) | DB auto-increment (single point) | Twitter Snowflake (chosen) ^alt-label Timestamp prefix ensures rough ordering; machine ID avoids coordination ^annotation

%%

Drawing

{
  "type": "excalidraw",
  "version": 2,
  "source": "https://excalidraw.com",
  "elements": [
    {
      "id": "svc-a",
      "type": "rectangle",
      "x": 40,
      "y": 60,
      "width": 110,
      "height": 40,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#f1f3f5",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "svc-a-text",
      "type": "text",
      "x": 55,
      "y": 72,
      "width": 80,
      "height": 20,
      "text": "Service A",
      "fontSize": 13,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "svc-b",
      "type": "rectangle",
      "x": 40,
      "y": 140,
      "width": 110,
      "height": 40,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#f1f3f5",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "svc-b-text",
      "type": "text",
      "x": 55,
      "y": 152,
      "width": 80,
      "height": 20,
      "text": "Service B",
      "fontSize": 13,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "svc-c",
      "type": "rectangle",
      "x": 40,
      "y": 220,
      "width": 110,
      "height": 40,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#f1f3f5",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "svc-c-text",
      "type": "text",
      "x": 55,
      "y": 232,
      "width": 80,
      "height": 20,
      "text": "Service C",
      "fontSize": 13,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "arrow-a-gen",
      "type": "arrow",
      "x": 150,
      "y": 80,
      "width": 80,
      "height": 70,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100,
      "points": [[0, 0], [80, 70]],
      "startArrowhead": null,
      "endArrowhead": "arrow",
      "label": {
        "text": "getNextId()",
        "fontSize": 10,
        "strokeColor": "#1e1e1e"
      }
    },
    {
      "id": "arrow-b-gen",
      "type": "arrow",
      "x": 150,
      "y": 160,
      "width": 80,
      "height": 0,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100,
      "points": [[0, 0], [80, 0]],
      "startArrowhead": null,
      "endArrowhead": "arrow",
      "label": {
        "text": "getNextId()",
        "fontSize": 10,
        "strokeColor": "#1e1e1e"
      }
    },
    {
      "id": "arrow-c-gen",
      "type": "arrow",
      "x": 150,
      "y": 240,
      "width": 80,
      "height": -80,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100,
      "points": [[0, 0], [80, -80]],
      "startArrowhead": null,
      "endArrowhead": "arrow",
      "label": {
        "text": "getNextId()",
        "fontSize": 10,
        "strokeColor": "#1e1e1e"
      }
    },
    {
      "id": "id-gen-svc",
      "type": "rectangle",
      "x": 230,
      "y": 60,
      "width": 260,
      "height": 180,
      "strokeColor": "#1971c2",
      "backgroundColor": "#d0ebff",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "id-gen-svc-title",
      "type": "text",
      "x": 245,
      "y": 70,
      "width": 230,
      "height": 20,
      "text": "ID Generator Service",
      "fontSize": 14,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1971c2",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "snowflake-label",
      "type": "text",
      "x": 245,
      "y": 96,
      "width": 230,
      "height": 18,
      "text": "Snowflake-style 64-bit ID",
      "fontSize": 12,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-sign",
      "type": "rectangle",
      "x": 242,
      "y": 118,
      "width": 30,
      "height": 30,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#dee2e6",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-sign-text",
      "type": "text",
      "x": 244,
      "y": 122,
      "width": 26,
      "height": 24,
      "text": "1b\nsign",
      "fontSize": 9,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-ts",
      "type": "rectangle",
      "x": 272,
      "y": 118,
      "width": 80,
      "height": 30,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#d0bfff",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-ts-text",
      "type": "text",
      "x": 274,
      "y": 125,
      "width": 76,
      "height": 18,
      "text": "41 bits timestamp",
      "fontSize": 9,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-dc",
      "type": "rectangle",
      "x": 352,
      "y": 118,
      "width": 46,
      "height": 30,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#a9e34b",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-dc-text",
      "type": "text",
      "x": 354,
      "y": 121,
      "width": 42,
      "height": 24,
      "text": "5 bits\ndc",
      "fontSize": 9,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-machine",
      "type": "rectangle",
      "x": 398,
      "y": 118,
      "width": 46,
      "height": 30,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#ffa94d",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-machine-text",
      "type": "text",
      "x": 400,
      "y": 121,
      "width": 42,
      "height": 24,
      "text": "5 bits\nmach",
      "fontSize": 9,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-seq",
      "type": "rectangle",
      "x": 444,
      "y": 118,
      "width": 46,
      "height": 30,
      "strokeColor": "#1e1e1e",
      "backgroundColor": "#74c0fc",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "bit-seq-text",
      "type": "text",
      "x": 446,
      "y": 121,
      "width": 42,
      "height": 24,
      "text": "12 bits\nseq",
      "fontSize": 9,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#1e1e1e",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "zk-svc",
      "type": "rectangle",
      "x": 270,
      "y": 300,
      "width": 180,
      "height": 44,
      "strokeColor": "#e67700",
      "backgroundColor": "#fff4e6",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "zk-svc-text",
      "type": "text",
      "x": 285,
      "y": 314,
      "width": 150,
      "height": 20,
      "text": "Zookeeper / etcd",
      "fontSize": 13,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#e67700",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "arrow-zk-gen",
      "type": "arrow",
      "x": 360,
      "y": 300,
      "width": 0,
      "height": -60,
      "strokeColor": "#e67700",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100,
      "points": [[0, 0], [0, -60]],
      "startArrowhead": null,
      "endArrowhead": "arrow",
      "label": {
        "text": "machine ID\nassignment",
        "fontSize": 10,
        "strokeColor": "#e67700"
      }
    },
    {
      "id": "downstream-db",
      "type": "ellipse",
      "x": 570,
      "y": 120,
      "width": 140,
      "height": 70,
      "strokeColor": "#2f9e44",
      "backgroundColor": "#ebfbee",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "downstream-db-text",
      "type": "text",
      "x": 585,
      "y": 147,
      "width": 110,
      "height": 20,
      "text": "Downstream DB",
      "fontSize": 12,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#2f9e44",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "arrow-gen-db",
      "type": "arrow",
      "x": 490,
      "y": 155,
      "width": 80,
      "height": 0,
      "strokeColor": "#2f9e44",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 2,
      "roughness": 1,
      "opacity": 100,
      "points": [[0, 0], [80, 0]],
      "startArrowhead": null,
      "endArrowhead": "arrow",
      "label": {
        "text": "sortable IDs",
        "fontSize": 10,
        "strokeColor": "#2f9e44"
      }
    },
    {
      "id": "alt-panel",
      "type": "rectangle",
      "x": 40,
      "y": 380,
      "width": 720,
      "height": 36,
      "strokeColor": "#868e96",
      "backgroundColor": "#f8f9fa",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "alt-text",
      "type": "text",
      "x": 55,
      "y": 390,
      "width": 690,
      "height": 20,
      "text": "Alternatives: UUID (128-bit, no ordering)  |  DB auto-increment (single point)  |  Twitter Snowflake (chosen)",
      "fontSize": 11,
      "fontFamily": 1,
      "textAlign": "center",
      "verticalAlign": "middle",
      "strokeColor": "#495057",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    },
    {
      "id": "annotation",
      "type": "text",
      "x": 40,
      "y": 430,
      "width": 680,
      "height": 20,
      "text": "Timestamp prefix ensures rough ordering; machine ID avoids coordination",
      "fontSize": 12,
      "fontFamily": 1,
      "textAlign": "left",
      "verticalAlign": "top",
      "strokeColor": "#e67700",
      "backgroundColor": "transparent",
      "fillStyle": "solid",
      "strokeWidth": 1,
      "roughness": 1,
      "opacity": 100
    }
  ],
  "appState": {
    "gridSize": null,
    "viewBackgroundColor": "#ffffff"
  },
  "files": {}
}

%%