[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-trigger-dev-staff-engineering-skills-clock-skew":3,"mdc-fuaup7-key":34,"related-org-trigger-dev-staff-engineering-skills-clock-skew":3440,"related-repo-trigger-dev-staff-engineering-skills-clock-skew":3607},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":12,"stars":23,"repoUrl":24,"updatedAt":25,"license":26,"forks":27,"topics":28,"repo":29,"sourceUrl":32,"mdContent":33},"staff-engineering-skills-clock-skew","prevent clock skew bugs in distributed systems","Prevent bugs caused by assuming clocks are synchronized or monotonic. Use when writing code that compares timestamps across machines, measures durations, sets lock expiry, orders distributed events, deduplicates by time window, or uses Date.now() for anything other than logging or display. Activates on patterns like Date.now() used for duration measurement, absolute timestamp expiry shared across machines, wall clock timestamps for event ordering, last-write-wins conflict resolution with timestamps, or timeout calculations using wall clock time.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},"trigger-dev","Trigger.dev","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Ftrigger-dev.jpg","triggerdotdev",[13,17,20],{"name":14,"slug":15,"type":16},"Architecture","architecture","tag",{"name":18,"slug":19,"type":16},"Engineering","engineering",{"name":21,"slug":22,"type":16},"Debugging","debugging",3,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills","2026-06-17T08:40:37.803541",null,1,[],{"repoUrl":24,"stars":23,"forks":27,"topics":30,"description":31},[],"Skills that give AI   coding agents staff-engineer instincts: recognizing and avoiding production failure modes like cardinality, idempotency, and race conditions.","https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills\u002Ftree\u002FHEAD\u002Fskills\u002Fstaff-engineering-skills-clock-skew","---\nname: staff-engineering-skills-clock-skew\ndescription: Prevent bugs caused by assuming clocks are synchronized or monotonic. Use when writing code that compares timestamps across machines, measures durations, sets lock expiry, orders distributed events, deduplicates by time window, or uses Date.now() for anything other than logging or display. Activates on patterns like Date.now() used for duration measurement, absolute timestamp expiry shared across machines, wall clock timestamps for event ordering, last-write-wins conflict resolution with timestamps, or timeout calculations using wall clock time.\n---\n\n# Clock Skew Trap\n\nYou used timestamps for ordering. Time disagreed. Before using `Date.now()` for anything other than logging or display, ask: **does correctness depend on this timestamp being accurate relative to another machine's clock, or relative to a previous reading on this machine?**\n\n## Two Kinds of Time\n\n| | Wall clock | Monotonic clock |\n|---|-----------|----------------|\n| **What it is** | Current time of day (NTP-synchronized) | Counter that only moves forward |\n| **Can go backward?** | Yes (NTP corrections, clock steps) | No, by definition |\n| **Comparable across machines?** | Only within clock skew margin (typically 1-100ms) | No -- only meaningful within one process |\n| **Use for** | Logging, display, human-readable timestamps | Durations, timeouts, elapsed time measurement |\n| **API** | `Date.now()`, `time.time()`, `System.currentTimeMillis()` | `process.hrtime.bigint()`, `time.monotonic()`, `time.Since()` |\n\n**The rule:** Use wall clock for humans. Use monotonic clock for measurement. Use logical clocks for distributed ordering.\n\n## Detection: When You're Misusing Time\n\n**Stop and fix if you see:**\n\n1. **`Date.now()` to measure a duration** -- `end - start` can go negative if NTP adjusts the clock between the two calls. Use a monotonic clock.\n2. **Timestamps compared across machines for ordering** -- \"A happened before B\" from different servers' `Date.now()`. If skew is 50ms and events are 30ms apart, you can't know the order. Use logical clocks or a centralized sequence.\n3. **Absolute timestamp expiry shared across machines** -- `{ expiresAt: Date.now() + 60000 }` written by Machine A, checked by Machine B. If B's clock is ahead, data expires early. Use relative TTLs.\n4. **Last-write-wins using wall clock timestamps** -- two writes within the skew window have undefined ordering. The \"winner\" is whichever machine's clock runs fast, not which write actually happened last.\n5. **Distributed lock expiry using wall clock** -- `if (Date.now() > lockExpiresAt)` checked on a different machine than acquired it. Skew makes the lock appear expired early (two holders) or late (delayed release).\n6. **Deduplication by timestamp proximity** -- \"ignore events within 100ms.\" 150ms of skew makes simultaneous events look 150ms apart (not deduped) or 150ms-apart events look simultaneous (wrongly deduped). Dedupe by unique ID.\n\n## When Wall Clock Is Fine\n\n```typescript\n\u002F\u002F Logging, display, analytics: humans read it; cross-machine order\u002Fsub-second accuracy isn't critical\nlogger.info(\"Request completed\", { timestamp: new Date().toISOString() });\nawait analytics.track(\"page_view\", { timestamp: Date.now() }); \u002F\u002F events\u002Fhour survives 100ms skew\n\n\u002F\u002F Single-machine record, not used for distributed ordering\nconst createdAt = new Date();\n```\n\nWall clock is fine when correctness doesn't depend on cross-machine comparison or exact duration measurement.\n\n## Patterns\n\n### Monotonic clock for durations\n\n```typescript\n\u002F\u002F Node.js -- always non-negative, even if NTP adjusts the wall clock mid-operation\nconst start = process.hrtime.bigint();\nawait doExpensiveOperation();\nconst elapsedMs = Number(process.hrtime.bigint() - start) \u002F 1_000_000;\n```\n\nEquivalents: Python `time.monotonic()` (diff is always non-negative); Go `time.Since(time.Now())` (uses the monotonic component automatically).\n\nUse monotonic clocks for: timeouts, latency measurement, rate-limiting windows, any `end - start`. They're only valid within a single process -- never compare across machines.\n\n### Relative TTLs instead of absolute expiry\n\n```typescript\n\u002F\u002F BAD: absolute expiry shared across machines -- B may disagree on when \"now\" is\nawait redis.pexpireat(\"session\", Date.now() + 3600_000); \u002F\u002F Machine A's \"1 hour from now\"\n\n\u002F\u002F GOOD: pass durations; let each system compute expiry from its own clock\nawait redis.expire(\"session\", 3600);             \u002F\u002F Redis's own clock\nawait redis.setex(key, ttlSeconds, payload);     \u002F\u002F same system sets and checks the timer\n```\n\nThe principle: pass durations (seconds, ms) between systems, not absolute timestamps.\n\n### Logical clocks for distributed ordering\n\nTo order events across machines, use a logical clock that guarantees causal ordering, not wall clock.\n\n```typescript\nclass LamportClock {\n  private counter = 0;\n  tick(): number { return ++this.counter; }\n  receive(senderClock: number): number {\n    this.counter = Math.max(this.counter, senderClock) + 1;\n    return this.counter;\n  }\n}\n\nconst event = {\n  type: \"order.created\",\n  logicalTime: clock.tick(),           \u002F\u002F ordering: monotonic, causally consistent\n  wallClock: new Date().toISOString(), \u002F\u002F humans: display\u002Fdebug only\n};\n```\n\nLamport clocks guarantee: if A causally precedes B, then A's logical time \u003C B's. They don't identify concurrent events (use vector clocks for that). For most apps, a centralized sequence generator (DB auto-increment, Redis `INCR`) is simpler and gives a total order.\n\n### Hybrid logical clocks (HLC)\n\nCombines wall clock (rough real-time correspondence) with a logical counter (causal ordering); used by CockroachDB. HLC timestamps sort first by wall time, then by logical counter -- so they roughly track real time while keeping causally related events ordered even when wall clocks collide.\n\n```typescript\nclass HybridLogicalClock {\n  private physicalTime = 0;\n  private logical = 0;\n\n  now(): { wallMs: number; logical: number } {\n    const pt = Date.now();\n    if (pt > this.physicalTime) { this.physicalTime = pt; this.logical = 0; }\n    else { this.logical++; }\n    return { wallMs: this.physicalTime, logical: this.logical };\n  }\n\n  receive(remote: { wallMs: number; logical: number }): { wallMs: number; logical: number } {\n    const maxPt = Math.max(Date.now(), this.physicalTime, remote.wallMs);\n    if (maxPt === this.physicalTime && maxPt === remote.wallMs) {\n      this.logical = Math.max(this.logical, remote.logical) + 1;\n    } else if (maxPt === this.physicalTime) {\n      this.logical++;\n    } else if (maxPt === remote.wallMs) {\n      this.logical = remote.logical + 1;\n    } else {\n      this.logical = 0;\n    }\n    this.physicalTime = maxPt;\n    return { wallMs: this.physicalTime, logical: this.logical };\n  }\n}\n```\n\n### Fencing tokens for distributed locks\n\nDon't rely on clock-based expiry alone. Hand out a monotonically increasing token at acquisition; the protected resource rejects stale ones.\n\n```typescript\nconst { token } = await acquireLockWithToken(\"resource-123\"); \u002F\u002F token monotonically increases\nawait protectedService.write({ data: newData, fencingToken: token });\n\n\u002F\u002F The protected service is the final arbiter, not the clock\nasync function write(req: { data: Data; fencingToken: number }) {\n  if (req.fencingToken \u003C= this.lastSeenToken) {\n    throw new Error(\"Stale fencing token -- lock was superseded\");\n  }\n  this.lastSeenToken = req.fencingToken;\n  await db.save(req.data);\n}\n```\n\nEven if skew makes two processes believe they hold the lock, only the highest token can write.\n\n## Anti-Patterns\n\n```typescript\n\u002F\u002F Duration with wall clock: can be negative\nconst elapsed = Date.now() - start; \u002F\u002F Use process.hrtime.bigint() instead\n\n\u002F\u002F Cross-machine ordering with wall clock: undefined within skew window\nevents.sort((a, b) => a.timestamp - b.timestamp); \u002F\u002F Timestamps from different machines\n\n\u002F\u002F Absolute expiry across machines: skew causes early\u002Flate expiry\nawait cache.set(key, { expiresAt: Date.now() + 60000 }); \u002F\u002F Pass ttlSeconds instead\n\n\u002F\u002F Last-write-wins with wall clock: \"last\" is undefined\nconst winner = writes.reduce((a, b) => a.timestamp > b.timestamp ? a : b);\n\n\u002F\u002F Lock expiry with wall clock: two holders possible\nif (Date.now() > lockExpiresAt) acquireLock(); \u002F\u002F Different machine's clock\n```\n\n## Related Traps\n\n- **Race Conditions** -- clock skew can create race conditions in distributed locks. Two processes both believe they hold an \"exclusive\" lock because their clocks disagree on whether the TTL has expired. Fencing tokens prevent the downstream corruption even when the lock fails.\n- **Retry Storms** -- timeout calculations using wall clock can fire early (clock jumps forward) or never fire (clock jumps backward). Use monotonic clocks for all timeout logic.\n- **Hot Partitions** -- time-based partition keys interact with clock skew at boundaries. Near midnight, machines with different clocks write to different date partitions, creating inconsistency.\n- **Idempotency** -- deduplication windows based on timestamps are unreliable when events come from machines with different clocks. Use unique IDs for deduplication, not timestamp proximity.\n",{"data":35,"body":36},{"name":4,"description":6},{"type":37,"children":38},"root",[39,48,69,76,248,258,264,272,371,377,652,657,663,670,823,843,855,861,1082,1087,1093,1098,1501,1514,1520,1525,2489,2495,2500,2914,2919,2925,3384,3390,3434],{"type":40,"tag":41,"props":42,"children":44},"element","h1",{"id":43},"clock-skew-trap",[45],{"type":46,"value":47},"text","Clock Skew Trap",{"type":40,"tag":49,"props":50,"children":51},"p",{},[52,54,61,63],{"type":46,"value":53},"You used timestamps for ordering. Time disagreed. Before using ",{"type":40,"tag":55,"props":56,"children":58},"code",{"className":57},[],[59],{"type":46,"value":60},"Date.now()",{"type":46,"value":62}," for anything other than logging or display, ask: ",{"type":40,"tag":64,"props":65,"children":66},"strong",{},[67],{"type":46,"value":68},"does correctness depend on this timestamp being accurate relative to another machine's clock, or relative to a previous reading on this machine?",{"type":40,"tag":70,"props":71,"children":73},"h2",{"id":72},"two-kinds-of-time",[74],{"type":46,"value":75},"Two Kinds of Time",{"type":40,"tag":77,"props":78,"children":79},"table",{},[80,102],{"type":40,"tag":81,"props":82,"children":83},"thead",{},[84],{"type":40,"tag":85,"props":86,"children":87},"tr",{},[88,92,97],{"type":40,"tag":89,"props":90,"children":91},"th",{},[],{"type":40,"tag":89,"props":93,"children":94},{},[95],{"type":46,"value":96},"Wall clock",{"type":40,"tag":89,"props":98,"children":99},{},[100],{"type":46,"value":101},"Monotonic clock",{"type":40,"tag":103,"props":104,"children":105},"tbody",{},[106,128,149,170,191],{"type":40,"tag":85,"props":107,"children":108},{},[109,118,123],{"type":40,"tag":110,"props":111,"children":112},"td",{},[113],{"type":40,"tag":64,"props":114,"children":115},{},[116],{"type":46,"value":117},"What it is",{"type":40,"tag":110,"props":119,"children":120},{},[121],{"type":46,"value":122},"Current time of day (NTP-synchronized)",{"type":40,"tag":110,"props":124,"children":125},{},[126],{"type":46,"value":127},"Counter that only moves forward",{"type":40,"tag":85,"props":129,"children":130},{},[131,139,144],{"type":40,"tag":110,"props":132,"children":133},{},[134],{"type":40,"tag":64,"props":135,"children":136},{},[137],{"type":46,"value":138},"Can go backward?",{"type":40,"tag":110,"props":140,"children":141},{},[142],{"type":46,"value":143},"Yes (NTP corrections, clock steps)",{"type":40,"tag":110,"props":145,"children":146},{},[147],{"type":46,"value":148},"No, by definition",{"type":40,"tag":85,"props":150,"children":151},{},[152,160,165],{"type":40,"tag":110,"props":153,"children":154},{},[155],{"type":40,"tag":64,"props":156,"children":157},{},[158],{"type":46,"value":159},"Comparable across machines?",{"type":40,"tag":110,"props":161,"children":162},{},[163],{"type":46,"value":164},"Only within clock skew margin (typically 1-100ms)",{"type":40,"tag":110,"props":166,"children":167},{},[168],{"type":46,"value":169},"No -- only meaningful within one process",{"type":40,"tag":85,"props":171,"children":172},{},[173,181,186],{"type":40,"tag":110,"props":174,"children":175},{},[176],{"type":40,"tag":64,"props":177,"children":178},{},[179],{"type":46,"value":180},"Use for",{"type":40,"tag":110,"props":182,"children":183},{},[184],{"type":46,"value":185},"Logging, display, human-readable timestamps",{"type":40,"tag":110,"props":187,"children":188},{},[189],{"type":46,"value":190},"Durations, timeouts, elapsed time measurement",{"type":40,"tag":85,"props":192,"children":193},{},[194,202,225],{"type":40,"tag":110,"props":195,"children":196},{},[197],{"type":40,"tag":64,"props":198,"children":199},{},[200],{"type":46,"value":201},"API",{"type":40,"tag":110,"props":203,"children":204},{},[205,210,212,218,219],{"type":40,"tag":55,"props":206,"children":208},{"className":207},[],[209],{"type":46,"value":60},{"type":46,"value":211},", ",{"type":40,"tag":55,"props":213,"children":215},{"className":214},[],[216],{"type":46,"value":217},"time.time()",{"type":46,"value":211},{"type":40,"tag":55,"props":220,"children":222},{"className":221},[],[223],{"type":46,"value":224},"System.currentTimeMillis()",{"type":40,"tag":110,"props":226,"children":227},{},[228,234,235,241,242],{"type":40,"tag":55,"props":229,"children":231},{"className":230},[],[232],{"type":46,"value":233},"process.hrtime.bigint()",{"type":46,"value":211},{"type":40,"tag":55,"props":236,"children":238},{"className":237},[],[239],{"type":46,"value":240},"time.monotonic()",{"type":46,"value":211},{"type":40,"tag":55,"props":243,"children":245},{"className":244},[],[246],{"type":46,"value":247},"time.Since()",{"type":40,"tag":49,"props":249,"children":250},{},[251,256],{"type":40,"tag":64,"props":252,"children":253},{},[254],{"type":46,"value":255},"The rule:",{"type":46,"value":257}," Use wall clock for humans. Use monotonic clock for measurement. Use logical clocks for distributed ordering.",{"type":40,"tag":70,"props":259,"children":261},{"id":260},"detection-when-youre-misusing-time",[262],{"type":46,"value":263},"Detection: When You're Misusing Time",{"type":40,"tag":49,"props":265,"children":266},{},[267],{"type":40,"tag":64,"props":268,"children":269},{},[270],{"type":46,"value":271},"Stop and fix if you see:",{"type":40,"tag":273,"props":274,"children":275},"ol",{},[276,300,317,334,344,361],{"type":40,"tag":277,"props":278,"children":279},"li",{},[280,290,292,298],{"type":40,"tag":64,"props":281,"children":282},{},[283,288],{"type":40,"tag":55,"props":284,"children":286},{"className":285},[],[287],{"type":46,"value":60},{"type":46,"value":289}," to measure a duration",{"type":46,"value":291}," -- ",{"type":40,"tag":55,"props":293,"children":295},{"className":294},[],[296],{"type":46,"value":297},"end - start",{"type":46,"value":299}," can go negative if NTP adjusts the clock between the two calls. Use a monotonic clock.",{"type":40,"tag":277,"props":301,"children":302},{},[303,308,310,315],{"type":40,"tag":64,"props":304,"children":305},{},[306],{"type":46,"value":307},"Timestamps compared across machines for ordering",{"type":46,"value":309}," -- \"A happened before B\" from different servers' ",{"type":40,"tag":55,"props":311,"children":313},{"className":312},[],[314],{"type":46,"value":60},{"type":46,"value":316},". If skew is 50ms and events are 30ms apart, you can't know the order. Use logical clocks or a centralized sequence.",{"type":40,"tag":277,"props":318,"children":319},{},[320,325,326,332],{"type":40,"tag":64,"props":321,"children":322},{},[323],{"type":46,"value":324},"Absolute timestamp expiry shared across machines",{"type":46,"value":291},{"type":40,"tag":55,"props":327,"children":329},{"className":328},[],[330],{"type":46,"value":331},"{ expiresAt: Date.now() + 60000 }",{"type":46,"value":333}," written by Machine A, checked by Machine B. If B's clock is ahead, data expires early. Use relative TTLs.",{"type":40,"tag":277,"props":335,"children":336},{},[337,342],{"type":40,"tag":64,"props":338,"children":339},{},[340],{"type":46,"value":341},"Last-write-wins using wall clock timestamps",{"type":46,"value":343}," -- two writes within the skew window have undefined ordering. The \"winner\" is whichever machine's clock runs fast, not which write actually happened last.",{"type":40,"tag":277,"props":345,"children":346},{},[347,352,353,359],{"type":40,"tag":64,"props":348,"children":349},{},[350],{"type":46,"value":351},"Distributed lock expiry using wall clock",{"type":46,"value":291},{"type":40,"tag":55,"props":354,"children":356},{"className":355},[],[357],{"type":46,"value":358},"if (Date.now() > lockExpiresAt)",{"type":46,"value":360}," checked on a different machine than acquired it. Skew makes the lock appear expired early (two holders) or late (delayed release).",{"type":40,"tag":277,"props":362,"children":363},{},[364,369],{"type":40,"tag":64,"props":365,"children":366},{},[367],{"type":46,"value":368},"Deduplication by timestamp proximity",{"type":46,"value":370}," -- \"ignore events within 100ms.\" 150ms of skew makes simultaneous events look 150ms apart (not deduped) or 150ms-apart events look simultaneous (wrongly deduped). Dedupe by unique ID.",{"type":40,"tag":70,"props":372,"children":374},{"id":373},"when-wall-clock-is-fine",[375],{"type":46,"value":376},"When Wall Clock Is Fine",{"type":40,"tag":378,"props":379,"children":384},"pre",{"className":380,"code":381,"language":382,"meta":383,"style":383},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Logging, display, analytics: humans read it; cross-machine order\u002Fsub-second accuracy isn't critical\nlogger.info(\"Request completed\", { timestamp: new Date().toISOString() });\nawait analytics.track(\"page_view\", { timestamp: Date.now() }); \u002F\u002F events\u002Fhour survives 100ms skew\n\n\u002F\u002F Single-machine record, not used for distributed ordering\nconst createdAt = new Date();\n","typescript","",[385],{"type":40,"tag":55,"props":386,"children":387},{"__ignoreMap":383},[388,399,506,597,607,616],{"type":40,"tag":389,"props":390,"children":392},"span",{"class":391,"line":27},"line",[393],{"type":40,"tag":389,"props":394,"children":396},{"style":395},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[397],{"type":46,"value":398},"\u002F\u002F Logging, display, analytics: humans read it; cross-machine order\u002Fsub-second accuracy isn't critical\n",{"type":40,"tag":389,"props":400,"children":402},{"class":391,"line":401},2,[403,409,415,421,426,431,437,441,446,451,457,462,467,472,477,481,486,491,496,501],{"type":40,"tag":389,"props":404,"children":406},{"style":405},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[407],{"type":46,"value":408},"logger",{"type":40,"tag":389,"props":410,"children":412},{"style":411},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[413],{"type":46,"value":414},".",{"type":40,"tag":389,"props":416,"children":418},{"style":417},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[419],{"type":46,"value":420},"info",{"type":40,"tag":389,"props":422,"children":423},{"style":405},[424],{"type":46,"value":425},"(",{"type":40,"tag":389,"props":427,"children":428},{"style":411},[429],{"type":46,"value":430},"\"",{"type":40,"tag":389,"props":432,"children":434},{"style":433},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[435],{"type":46,"value":436},"Request completed",{"type":40,"tag":389,"props":438,"children":439},{"style":411},[440],{"type":46,"value":430},{"type":40,"tag":389,"props":442,"children":443},{"style":411},[444],{"type":46,"value":445},",",{"type":40,"tag":389,"props":447,"children":448},{"style":411},[449],{"type":46,"value":450}," {",{"type":40,"tag":389,"props":452,"children":454},{"style":453},"--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178",[455],{"type":46,"value":456}," timestamp",{"type":40,"tag":389,"props":458,"children":459},{"style":411},[460],{"type":46,"value":461},":",{"type":40,"tag":389,"props":463,"children":464},{"style":411},[465],{"type":46,"value":466}," new",{"type":40,"tag":389,"props":468,"children":469},{"style":417},[470],{"type":46,"value":471}," Date",{"type":40,"tag":389,"props":473,"children":474},{"style":405},[475],{"type":46,"value":476},"()",{"type":40,"tag":389,"props":478,"children":479},{"style":411},[480],{"type":46,"value":414},{"type":40,"tag":389,"props":482,"children":483},{"style":417},[484],{"type":46,"value":485},"toISOString",{"type":40,"tag":389,"props":487,"children":488},{"style":405},[489],{"type":46,"value":490},"() ",{"type":40,"tag":389,"props":492,"children":493},{"style":411},[494],{"type":46,"value":495},"}",{"type":40,"tag":389,"props":497,"children":498},{"style":405},[499],{"type":46,"value":500},")",{"type":40,"tag":389,"props":502,"children":503},{"style":411},[504],{"type":46,"value":505},";\n",{"type":40,"tag":389,"props":507,"children":508},{"class":391,"line":23},[509,515,520,524,529,533,537,542,546,550,554,558,562,566,570,575,579,583,587,592],{"type":40,"tag":389,"props":510,"children":512},{"style":511},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[513],{"type":46,"value":514},"await",{"type":40,"tag":389,"props":516,"children":517},{"style":405},[518],{"type":46,"value":519}," analytics",{"type":40,"tag":389,"props":521,"children":522},{"style":411},[523],{"type":46,"value":414},{"type":40,"tag":389,"props":525,"children":526},{"style":417},[527],{"type":46,"value":528},"track",{"type":40,"tag":389,"props":530,"children":531},{"style":405},[532],{"type":46,"value":425},{"type":40,"tag":389,"props":534,"children":535},{"style":411},[536],{"type":46,"value":430},{"type":40,"tag":389,"props":538,"children":539},{"style":433},[540],{"type":46,"value":541},"page_view",{"type":40,"tag":389,"props":543,"children":544},{"style":411},[545],{"type":46,"value":430},{"type":40,"tag":389,"props":547,"children":548},{"style":411},[549],{"type":46,"value":445},{"type":40,"tag":389,"props":551,"children":552},{"style":411},[553],{"type":46,"value":450},{"type":40,"tag":389,"props":555,"children":556},{"style":453},[557],{"type":46,"value":456},{"type":40,"tag":389,"props":559,"children":560},{"style":411},[561],{"type":46,"value":461},{"type":40,"tag":389,"props":563,"children":564},{"style":405},[565],{"type":46,"value":471},{"type":40,"tag":389,"props":567,"children":568},{"style":411},[569],{"type":46,"value":414},{"type":40,"tag":389,"props":571,"children":572},{"style":417},[573],{"type":46,"value":574},"now",{"type":40,"tag":389,"props":576,"children":577},{"style":405},[578],{"type":46,"value":490},{"type":40,"tag":389,"props":580,"children":581},{"style":411},[582],{"type":46,"value":495},{"type":40,"tag":389,"props":584,"children":585},{"style":405},[586],{"type":46,"value":500},{"type":40,"tag":389,"props":588,"children":589},{"style":411},[590],{"type":46,"value":591},";",{"type":40,"tag":389,"props":593,"children":594},{"style":395},[595],{"type":46,"value":596}," \u002F\u002F events\u002Fhour survives 100ms skew\n",{"type":40,"tag":389,"props":598,"children":600},{"class":391,"line":599},4,[601],{"type":40,"tag":389,"props":602,"children":604},{"emptyLinePlaceholder":603},true,[605],{"type":46,"value":606},"\n",{"type":40,"tag":389,"props":608,"children":610},{"class":391,"line":609},5,[611],{"type":40,"tag":389,"props":612,"children":613},{"style":395},[614],{"type":46,"value":615},"\u002F\u002F Single-machine record, not used for distributed ordering\n",{"type":40,"tag":389,"props":617,"children":619},{"class":391,"line":618},6,[620,626,631,636,640,644,648],{"type":40,"tag":389,"props":621,"children":623},{"style":622},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[624],{"type":46,"value":625},"const",{"type":40,"tag":389,"props":627,"children":628},{"style":405},[629],{"type":46,"value":630}," createdAt ",{"type":40,"tag":389,"props":632,"children":633},{"style":411},[634],{"type":46,"value":635},"=",{"type":40,"tag":389,"props":637,"children":638},{"style":411},[639],{"type":46,"value":466},{"type":40,"tag":389,"props":641,"children":642},{"style":417},[643],{"type":46,"value":471},{"type":40,"tag":389,"props":645,"children":646},{"style":405},[647],{"type":46,"value":476},{"type":40,"tag":389,"props":649,"children":650},{"style":411},[651],{"type":46,"value":505},{"type":40,"tag":49,"props":653,"children":654},{},[655],{"type":46,"value":656},"Wall clock is fine when correctness doesn't depend on cross-machine comparison or exact duration measurement.",{"type":40,"tag":70,"props":658,"children":660},{"id":659},"patterns",[661],{"type":46,"value":662},"Patterns",{"type":40,"tag":664,"props":665,"children":667},"h3",{"id":666},"monotonic-clock-for-durations",[668],{"type":46,"value":669},"Monotonic clock for durations",{"type":40,"tag":378,"props":671,"children":673},{"className":380,"code":672,"language":382,"meta":383,"style":383},"\u002F\u002F Node.js -- always non-negative, even if NTP adjusts the wall clock mid-operation\nconst start = process.hrtime.bigint();\nawait doExpensiveOperation();\nconst elapsedMs = Number(process.hrtime.bigint() - start) \u002F 1_000_000;\n",[674],{"type":40,"tag":55,"props":675,"children":676},{"__ignoreMap":383},[677,685,732,752],{"type":40,"tag":389,"props":678,"children":679},{"class":391,"line":27},[680],{"type":40,"tag":389,"props":681,"children":682},{"style":395},[683],{"type":46,"value":684},"\u002F\u002F Node.js -- always non-negative, even if NTP adjusts the wall clock mid-operation\n",{"type":40,"tag":389,"props":686,"children":687},{"class":391,"line":401},[688,692,697,701,706,710,715,719,724,728],{"type":40,"tag":389,"props":689,"children":690},{"style":622},[691],{"type":46,"value":625},{"type":40,"tag":389,"props":693,"children":694},{"style":405},[695],{"type":46,"value":696}," start ",{"type":40,"tag":389,"props":698,"children":699},{"style":411},[700],{"type":46,"value":635},{"type":40,"tag":389,"props":702,"children":703},{"style":405},[704],{"type":46,"value":705}," process",{"type":40,"tag":389,"props":707,"children":708},{"style":411},[709],{"type":46,"value":414},{"type":40,"tag":389,"props":711,"children":712},{"style":405},[713],{"type":46,"value":714},"hrtime",{"type":40,"tag":389,"props":716,"children":717},{"style":411},[718],{"type":46,"value":414},{"type":40,"tag":389,"props":720,"children":721},{"style":417},[722],{"type":46,"value":723},"bigint",{"type":40,"tag":389,"props":725,"children":726},{"style":405},[727],{"type":46,"value":476},{"type":40,"tag":389,"props":729,"children":730},{"style":411},[731],{"type":46,"value":505},{"type":40,"tag":389,"props":733,"children":734},{"class":391,"line":23},[735,739,744,748],{"type":40,"tag":389,"props":736,"children":737},{"style":511},[738],{"type":46,"value":514},{"type":40,"tag":389,"props":740,"children":741},{"style":417},[742],{"type":46,"value":743}," doExpensiveOperation",{"type":40,"tag":389,"props":745,"children":746},{"style":405},[747],{"type":46,"value":476},{"type":40,"tag":389,"props":749,"children":750},{"style":411},[751],{"type":46,"value":505},{"type":40,"tag":389,"props":753,"children":754},{"class":391,"line":599},[755,759,764,768,773,778,782,786,790,794,798,803,808,813,819],{"type":40,"tag":389,"props":756,"children":757},{"style":622},[758],{"type":46,"value":625},{"type":40,"tag":389,"props":760,"children":761},{"style":405},[762],{"type":46,"value":763}," elapsedMs ",{"type":40,"tag":389,"props":765,"children":766},{"style":411},[767],{"type":46,"value":635},{"type":40,"tag":389,"props":769,"children":770},{"style":417},[771],{"type":46,"value":772}," Number",{"type":40,"tag":389,"props":774,"children":775},{"style":405},[776],{"type":46,"value":777},"(process",{"type":40,"tag":389,"props":779,"children":780},{"style":411},[781],{"type":46,"value":414},{"type":40,"tag":389,"props":783,"children":784},{"style":405},[785],{"type":46,"value":714},{"type":40,"tag":389,"props":787,"children":788},{"style":411},[789],{"type":46,"value":414},{"type":40,"tag":389,"props":791,"children":792},{"style":417},[793],{"type":46,"value":723},{"type":40,"tag":389,"props":795,"children":796},{"style":405},[797],{"type":46,"value":490},{"type":40,"tag":389,"props":799,"children":800},{"style":411},[801],{"type":46,"value":802},"-",{"type":40,"tag":389,"props":804,"children":805},{"style":405},[806],{"type":46,"value":807}," start) ",{"type":40,"tag":389,"props":809,"children":810},{"style":411},[811],{"type":46,"value":812},"\u002F",{"type":40,"tag":389,"props":814,"children":816},{"style":815},"--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C",[817],{"type":46,"value":818}," 1_000_000",{"type":40,"tag":389,"props":820,"children":821},{"style":411},[822],{"type":46,"value":505},{"type":40,"tag":49,"props":824,"children":825},{},[826,828,833,835,841],{"type":46,"value":827},"Equivalents: Python ",{"type":40,"tag":55,"props":829,"children":831},{"className":830},[],[832],{"type":46,"value":240},{"type":46,"value":834}," (diff is always non-negative); Go ",{"type":40,"tag":55,"props":836,"children":838},{"className":837},[],[839],{"type":46,"value":840},"time.Since(time.Now())",{"type":46,"value":842}," (uses the monotonic component automatically).",{"type":40,"tag":49,"props":844,"children":845},{},[846,848,853],{"type":46,"value":847},"Use monotonic clocks for: timeouts, latency measurement, rate-limiting windows, any ",{"type":40,"tag":55,"props":849,"children":851},{"className":850},[],[852],{"type":46,"value":297},{"type":46,"value":854},". They're only valid within a single process -- never compare across machines.",{"type":40,"tag":664,"props":856,"children":858},{"id":857},"relative-ttls-instead-of-absolute-expiry",[859],{"type":46,"value":860},"Relative TTLs instead of absolute expiry",{"type":40,"tag":378,"props":862,"children":864},{"className":380,"code":863,"language":382,"meta":383,"style":383},"\u002F\u002F BAD: absolute expiry shared across machines -- B may disagree on when \"now\" is\nawait redis.pexpireat(\"session\", Date.now() + 3600_000); \u002F\u002F Machine A's \"1 hour from now\"\n\n\u002F\u002F GOOD: pass durations; let each system compute expiry from its own clock\nawait redis.expire(\"session\", 3600);             \u002F\u002F Redis's own clock\nawait redis.setex(key, ttlSeconds, payload);     \u002F\u002F same system sets and checks the timer\n",[865],{"type":40,"tag":55,"props":866,"children":867},{"__ignoreMap":383},[868,876,957,964,972,1030],{"type":40,"tag":389,"props":869,"children":870},{"class":391,"line":27},[871],{"type":40,"tag":389,"props":872,"children":873},{"style":395},[874],{"type":46,"value":875},"\u002F\u002F BAD: absolute expiry shared across machines -- B may disagree on when \"now\" is\n",{"type":40,"tag":389,"props":877,"children":878},{"class":391,"line":401},[879,883,888,892,897,901,905,910,914,918,922,926,930,934,939,944,948,952],{"type":40,"tag":389,"props":880,"children":881},{"style":511},[882],{"type":46,"value":514},{"type":40,"tag":389,"props":884,"children":885},{"style":405},[886],{"type":46,"value":887}," redis",{"type":40,"tag":389,"props":889,"children":890},{"style":411},[891],{"type":46,"value":414},{"type":40,"tag":389,"props":893,"children":894},{"style":417},[895],{"type":46,"value":896},"pexpireat",{"type":40,"tag":389,"props":898,"children":899},{"style":405},[900],{"type":46,"value":425},{"type":40,"tag":389,"props":902,"children":903},{"style":411},[904],{"type":46,"value":430},{"type":40,"tag":389,"props":906,"children":907},{"style":433},[908],{"type":46,"value":909},"session",{"type":40,"tag":389,"props":911,"children":912},{"style":411},[913],{"type":46,"value":430},{"type":40,"tag":389,"props":915,"children":916},{"style":411},[917],{"type":46,"value":445},{"type":40,"tag":389,"props":919,"children":920},{"style":405},[921],{"type":46,"value":471},{"type":40,"tag":389,"props":923,"children":924},{"style":411},[925],{"type":46,"value":414},{"type":40,"tag":389,"props":927,"children":928},{"style":417},[929],{"type":46,"value":574},{"type":40,"tag":389,"props":931,"children":932},{"style":405},[933],{"type":46,"value":490},{"type":40,"tag":389,"props":935,"children":936},{"style":411},[937],{"type":46,"value":938},"+",{"type":40,"tag":389,"props":940,"children":941},{"style":815},[942],{"type":46,"value":943}," 3600_000",{"type":40,"tag":389,"props":945,"children":946},{"style":405},[947],{"type":46,"value":500},{"type":40,"tag":389,"props":949,"children":950},{"style":411},[951],{"type":46,"value":591},{"type":40,"tag":389,"props":953,"children":954},{"style":395},[955],{"type":46,"value":956}," \u002F\u002F Machine A's \"1 hour from now\"\n",{"type":40,"tag":389,"props":958,"children":959},{"class":391,"line":23},[960],{"type":40,"tag":389,"props":961,"children":962},{"emptyLinePlaceholder":603},[963],{"type":46,"value":606},{"type":40,"tag":389,"props":965,"children":966},{"class":391,"line":599},[967],{"type":40,"tag":389,"props":968,"children":969},{"style":395},[970],{"type":46,"value":971},"\u002F\u002F GOOD: pass durations; let each system compute expiry from its own clock\n",{"type":40,"tag":389,"props":973,"children":974},{"class":391,"line":609},[975,979,983,987,992,996,1000,1004,1008,1012,1017,1021,1025],{"type":40,"tag":389,"props":976,"children":977},{"style":511},[978],{"type":46,"value":514},{"type":40,"tag":389,"props":980,"children":981},{"style":405},[982],{"type":46,"value":887},{"type":40,"tag":389,"props":984,"children":985},{"style":411},[986],{"type":46,"value":414},{"type":40,"tag":389,"props":988,"children":989},{"style":417},[990],{"type":46,"value":991},"expire",{"type":40,"tag":389,"props":993,"children":994},{"style":405},[995],{"type":46,"value":425},{"type":40,"tag":389,"props":997,"children":998},{"style":411},[999],{"type":46,"value":430},{"type":40,"tag":389,"props":1001,"children":1002},{"style":433},[1003],{"type":46,"value":909},{"type":40,"tag":389,"props":1005,"children":1006},{"style":411},[1007],{"type":46,"value":430},{"type":40,"tag":389,"props":1009,"children":1010},{"style":411},[1011],{"type":46,"value":445},{"type":40,"tag":389,"props":1013,"children":1014},{"style":815},[1015],{"type":46,"value":1016}," 3600",{"type":40,"tag":389,"props":1018,"children":1019},{"style":405},[1020],{"type":46,"value":500},{"type":40,"tag":389,"props":1022,"children":1023},{"style":411},[1024],{"type":46,"value":591},{"type":40,"tag":389,"props":1026,"children":1027},{"style":395},[1028],{"type":46,"value":1029},"             \u002F\u002F Redis's own clock\n",{"type":40,"tag":389,"props":1031,"children":1032},{"class":391,"line":618},[1033,1037,1041,1045,1050,1055,1059,1064,1068,1073,1077],{"type":40,"tag":389,"props":1034,"children":1035},{"style":511},[1036],{"type":46,"value":514},{"type":40,"tag":389,"props":1038,"children":1039},{"style":405},[1040],{"type":46,"value":887},{"type":40,"tag":389,"props":1042,"children":1043},{"style":411},[1044],{"type":46,"value":414},{"type":40,"tag":389,"props":1046,"children":1047},{"style":417},[1048],{"type":46,"value":1049},"setex",{"type":40,"tag":389,"props":1051,"children":1052},{"style":405},[1053],{"type":46,"value":1054},"(key",{"type":40,"tag":389,"props":1056,"children":1057},{"style":411},[1058],{"type":46,"value":445},{"type":40,"tag":389,"props":1060,"children":1061},{"style":405},[1062],{"type":46,"value":1063}," ttlSeconds",{"type":40,"tag":389,"props":1065,"children":1066},{"style":411},[1067],{"type":46,"value":445},{"type":40,"tag":389,"props":1069,"children":1070},{"style":405},[1071],{"type":46,"value":1072}," payload)",{"type":40,"tag":389,"props":1074,"children":1075},{"style":411},[1076],{"type":46,"value":591},{"type":40,"tag":389,"props":1078,"children":1079},{"style":395},[1080],{"type":46,"value":1081},"     \u002F\u002F same system sets and checks the timer\n",{"type":40,"tag":49,"props":1083,"children":1084},{},[1085],{"type":46,"value":1086},"The principle: pass durations (seconds, ms) between systems, not absolute timestamps.",{"type":40,"tag":664,"props":1088,"children":1090},{"id":1089},"logical-clocks-for-distributed-ordering",[1091],{"type":46,"value":1092},"Logical clocks for distributed ordering",{"type":40,"tag":49,"props":1094,"children":1095},{},[1096],{"type":46,"value":1097},"To order events across machines, use a logical clock that guarantees causal ordering, not wall clock.",{"type":40,"tag":378,"props":1099,"children":1101},{"className":380,"code":1100,"language":382,"meta":383,"style":383},"class LamportClock {\n  private counter = 0;\n  tick(): number { return ++this.counter; }\n  receive(senderClock: number): number {\n    this.counter = Math.max(this.counter, senderClock) + 1;\n    return this.counter;\n  }\n}\n\nconst event = {\n  type: \"order.created\",\n  logicalTime: clock.tick(),           \u002F\u002F ordering: monotonic, causally consistent\n  wallClock: new Date().toISOString(), \u002F\u002F humans: display\u002Fdebug only\n};\n",[1102],{"type":40,"tag":55,"props":1103,"children":1104},{"__ignoreMap":383},[1105,1124,1151,1197,1236,1306,1327,1336,1345,1353,1374,1406,1446,1492],{"type":40,"tag":389,"props":1106,"children":1107},{"class":391,"line":27},[1108,1113,1119],{"type":40,"tag":389,"props":1109,"children":1110},{"style":622},[1111],{"type":46,"value":1112},"class",{"type":40,"tag":389,"props":1114,"children":1116},{"style":1115},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[1117],{"type":46,"value":1118}," LamportClock",{"type":40,"tag":389,"props":1120,"children":1121},{"style":411},[1122],{"type":46,"value":1123}," {\n",{"type":40,"tag":389,"props":1125,"children":1126},{"class":391,"line":401},[1127,1132,1137,1142,1147],{"type":40,"tag":389,"props":1128,"children":1129},{"style":622},[1130],{"type":46,"value":1131},"  private",{"type":40,"tag":389,"props":1133,"children":1134},{"style":453},[1135],{"type":46,"value":1136}," counter",{"type":40,"tag":389,"props":1138,"children":1139},{"style":411},[1140],{"type":46,"value":1141}," =",{"type":40,"tag":389,"props":1143,"children":1144},{"style":815},[1145],{"type":46,"value":1146}," 0",{"type":40,"tag":389,"props":1148,"children":1149},{"style":411},[1150],{"type":46,"value":505},{"type":40,"tag":389,"props":1152,"children":1153},{"class":391,"line":23},[1154,1159,1164,1169,1173,1178,1183,1188,1192],{"type":40,"tag":389,"props":1155,"children":1156},{"style":453},[1157],{"type":46,"value":1158},"  tick",{"type":40,"tag":389,"props":1160,"children":1161},{"style":411},[1162],{"type":46,"value":1163},"():",{"type":40,"tag":389,"props":1165,"children":1166},{"style":1115},[1167],{"type":46,"value":1168}," number",{"type":40,"tag":389,"props":1170,"children":1171},{"style":411},[1172],{"type":46,"value":450},{"type":40,"tag":389,"props":1174,"children":1175},{"style":511},[1176],{"type":46,"value":1177}," return",{"type":40,"tag":389,"props":1179,"children":1180},{"style":411},[1181],{"type":46,"value":1182}," ++this.",{"type":40,"tag":389,"props":1184,"children":1185},{"style":405},[1186],{"type":46,"value":1187},"counter",{"type":40,"tag":389,"props":1189,"children":1190},{"style":411},[1191],{"type":46,"value":591},{"type":40,"tag":389,"props":1193,"children":1194},{"style":411},[1195],{"type":46,"value":1196}," }\n",{"type":40,"tag":389,"props":1198,"children":1199},{"class":391,"line":599},[1200,1205,1209,1215,1219,1223,1228,1232],{"type":40,"tag":389,"props":1201,"children":1202},{"style":453},[1203],{"type":46,"value":1204},"  receive",{"type":40,"tag":389,"props":1206,"children":1207},{"style":411},[1208],{"type":46,"value":425},{"type":40,"tag":389,"props":1210,"children":1212},{"style":1211},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic",[1213],{"type":46,"value":1214},"senderClock",{"type":40,"tag":389,"props":1216,"children":1217},{"style":411},[1218],{"type":46,"value":461},{"type":40,"tag":389,"props":1220,"children":1221},{"style":1115},[1222],{"type":46,"value":1168},{"type":40,"tag":389,"props":1224,"children":1225},{"style":411},[1226],{"type":46,"value":1227},"):",{"type":40,"tag":389,"props":1229,"children":1230},{"style":1115},[1231],{"type":46,"value":1168},{"type":40,"tag":389,"props":1233,"children":1234},{"style":411},[1235],{"type":46,"value":1123},{"type":40,"tag":389,"props":1237,"children":1238},{"class":391,"line":609},[1239,1244,1248,1252,1257,1261,1266,1270,1275,1279,1283,1288,1293,1297,1302],{"type":40,"tag":389,"props":1240,"children":1241},{"style":411},[1242],{"type":46,"value":1243},"    this.",{"type":40,"tag":389,"props":1245,"children":1246},{"style":405},[1247],{"type":46,"value":1187},{"type":40,"tag":389,"props":1249,"children":1250},{"style":411},[1251],{"type":46,"value":1141},{"type":40,"tag":389,"props":1253,"children":1254},{"style":405},[1255],{"type":46,"value":1256}," Math",{"type":40,"tag":389,"props":1258,"children":1259},{"style":411},[1260],{"type":46,"value":414},{"type":40,"tag":389,"props":1262,"children":1263},{"style":417},[1264],{"type":46,"value":1265},"max",{"type":40,"tag":389,"props":1267,"children":1268},{"style":453},[1269],{"type":46,"value":425},{"type":40,"tag":389,"props":1271,"children":1272},{"style":411},[1273],{"type":46,"value":1274},"this.",{"type":40,"tag":389,"props":1276,"children":1277},{"style":405},[1278],{"type":46,"value":1187},{"type":40,"tag":389,"props":1280,"children":1281},{"style":411},[1282],{"type":46,"value":445},{"type":40,"tag":389,"props":1284,"children":1285},{"style":405},[1286],{"type":46,"value":1287}," senderClock",{"type":40,"tag":389,"props":1289,"children":1290},{"style":453},[1291],{"type":46,"value":1292},") ",{"type":40,"tag":389,"props":1294,"children":1295},{"style":411},[1296],{"type":46,"value":938},{"type":40,"tag":389,"props":1298,"children":1299},{"style":815},[1300],{"type":46,"value":1301}," 1",{"type":40,"tag":389,"props":1303,"children":1304},{"style":411},[1305],{"type":46,"value":505},{"type":40,"tag":389,"props":1307,"children":1308},{"class":391,"line":618},[1309,1314,1319,1323],{"type":40,"tag":389,"props":1310,"children":1311},{"style":511},[1312],{"type":46,"value":1313},"    return",{"type":40,"tag":389,"props":1315,"children":1316},{"style":411},[1317],{"type":46,"value":1318}," this.",{"type":40,"tag":389,"props":1320,"children":1321},{"style":405},[1322],{"type":46,"value":1187},{"type":40,"tag":389,"props":1324,"children":1325},{"style":411},[1326],{"type":46,"value":505},{"type":40,"tag":389,"props":1328,"children":1330},{"class":391,"line":1329},7,[1331],{"type":40,"tag":389,"props":1332,"children":1333},{"style":411},[1334],{"type":46,"value":1335},"  }\n",{"type":40,"tag":389,"props":1337,"children":1339},{"class":391,"line":1338},8,[1340],{"type":40,"tag":389,"props":1341,"children":1342},{"style":411},[1343],{"type":46,"value":1344},"}\n",{"type":40,"tag":389,"props":1346,"children":1348},{"class":391,"line":1347},9,[1349],{"type":40,"tag":389,"props":1350,"children":1351},{"emptyLinePlaceholder":603},[1352],{"type":46,"value":606},{"type":40,"tag":389,"props":1354,"children":1356},{"class":391,"line":1355},10,[1357,1361,1366,1370],{"type":40,"tag":389,"props":1358,"children":1359},{"style":622},[1360],{"type":46,"value":625},{"type":40,"tag":389,"props":1362,"children":1363},{"style":405},[1364],{"type":46,"value":1365}," event ",{"type":40,"tag":389,"props":1367,"children":1368},{"style":411},[1369],{"type":46,"value":635},{"type":40,"tag":389,"props":1371,"children":1372},{"style":411},[1373],{"type":46,"value":1123},{"type":40,"tag":389,"props":1375,"children":1377},{"class":391,"line":1376},11,[1378,1383,1387,1392,1397,1401],{"type":40,"tag":389,"props":1379,"children":1380},{"style":453},[1381],{"type":46,"value":1382},"  type",{"type":40,"tag":389,"props":1384,"children":1385},{"style":411},[1386],{"type":46,"value":461},{"type":40,"tag":389,"props":1388,"children":1389},{"style":411},[1390],{"type":46,"value":1391}," \"",{"type":40,"tag":389,"props":1393,"children":1394},{"style":433},[1395],{"type":46,"value":1396},"order.created",{"type":40,"tag":389,"props":1398,"children":1399},{"style":411},[1400],{"type":46,"value":430},{"type":40,"tag":389,"props":1402,"children":1403},{"style":411},[1404],{"type":46,"value":1405},",\n",{"type":40,"tag":389,"props":1407,"children":1409},{"class":391,"line":1408},12,[1410,1415,1419,1424,1428,1433,1437,1441],{"type":40,"tag":389,"props":1411,"children":1412},{"style":453},[1413],{"type":46,"value":1414},"  logicalTime",{"type":40,"tag":389,"props":1416,"children":1417},{"style":411},[1418],{"type":46,"value":461},{"type":40,"tag":389,"props":1420,"children":1421},{"style":405},[1422],{"type":46,"value":1423}," clock",{"type":40,"tag":389,"props":1425,"children":1426},{"style":411},[1427],{"type":46,"value":414},{"type":40,"tag":389,"props":1429,"children":1430},{"style":417},[1431],{"type":46,"value":1432},"tick",{"type":40,"tag":389,"props":1434,"children":1435},{"style":405},[1436],{"type":46,"value":476},{"type":40,"tag":389,"props":1438,"children":1439},{"style":411},[1440],{"type":46,"value":445},{"type":40,"tag":389,"props":1442,"children":1443},{"style":395},[1444],{"type":46,"value":1445},"           \u002F\u002F ordering: monotonic, causally consistent\n",{"type":40,"tag":389,"props":1447,"children":1449},{"class":391,"line":1448},13,[1450,1455,1459,1463,1467,1471,1475,1479,1483,1487],{"type":40,"tag":389,"props":1451,"children":1452},{"style":453},[1453],{"type":46,"value":1454},"  wallClock",{"type":40,"tag":389,"props":1456,"children":1457},{"style":411},[1458],{"type":46,"value":461},{"type":40,"tag":389,"props":1460,"children":1461},{"style":411},[1462],{"type":46,"value":466},{"type":40,"tag":389,"props":1464,"children":1465},{"style":417},[1466],{"type":46,"value":471},{"type":40,"tag":389,"props":1468,"children":1469},{"style":405},[1470],{"type":46,"value":476},{"type":40,"tag":389,"props":1472,"children":1473},{"style":411},[1474],{"type":46,"value":414},{"type":40,"tag":389,"props":1476,"children":1477},{"style":417},[1478],{"type":46,"value":485},{"type":40,"tag":389,"props":1480,"children":1481},{"style":405},[1482],{"type":46,"value":476},{"type":40,"tag":389,"props":1484,"children":1485},{"style":411},[1486],{"type":46,"value":445},{"type":40,"tag":389,"props":1488,"children":1489},{"style":395},[1490],{"type":46,"value":1491}," \u002F\u002F humans: display\u002Fdebug only\n",{"type":40,"tag":389,"props":1493,"children":1495},{"class":391,"line":1494},14,[1496],{"type":40,"tag":389,"props":1497,"children":1498},{"style":411},[1499],{"type":46,"value":1500},"};\n",{"type":40,"tag":49,"props":1502,"children":1503},{},[1504,1506,1512],{"type":46,"value":1505},"Lamport clocks guarantee: if A causally precedes B, then A's logical time \u003C B's. They don't identify concurrent events (use vector clocks for that). For most apps, a centralized sequence generator (DB auto-increment, Redis ",{"type":40,"tag":55,"props":1507,"children":1509},{"className":1508},[],[1510],{"type":46,"value":1511},"INCR",{"type":46,"value":1513},") is simpler and gives a total order.",{"type":40,"tag":664,"props":1515,"children":1517},{"id":1516},"hybrid-logical-clocks-hlc",[1518],{"type":46,"value":1519},"Hybrid logical clocks (HLC)",{"type":40,"tag":49,"props":1521,"children":1522},{},[1523],{"type":46,"value":1524},"Combines wall clock (rough real-time correspondence) with a logical counter (causal ordering); used by CockroachDB. HLC timestamps sort first by wall time, then by logical counter -- so they roughly track real time while keeping causally related events ordered even when wall clocks collide.",{"type":40,"tag":378,"props":1526,"children":1528},{"className":380,"code":1527,"language":382,"meta":383,"style":383},"class HybridLogicalClock {\n  private physicalTime = 0;\n  private logical = 0;\n\n  now(): { wallMs: number; logical: number } {\n    const pt = Date.now();\n    if (pt > this.physicalTime) { this.physicalTime = pt; this.logical = 0; }\n    else { this.logical++; }\n    return { wallMs: this.physicalTime, logical: this.logical };\n  }\n\n  receive(remote: { wallMs: number; logical: number }): { wallMs: number; logical: number } {\n    const maxPt = Math.max(Date.now(), this.physicalTime, remote.wallMs);\n    if (maxPt === this.physicalTime && maxPt === remote.wallMs) {\n      this.logical = Math.max(this.logical, remote.logical) + 1;\n    } else if (maxPt === this.physicalTime) {\n      this.logical++;\n    } else if (maxPt === remote.wallMs) {\n      this.logical = remote.logical + 1;\n    } else {\n      this.logical = 0;\n    }\n    this.physicalTime = maxPt;\n    return { wallMs: this.physicalTime, logical: this.logical };\n  }\n}\n",[1529],{"type":40,"tag":55,"props":1530,"children":1531},{"__ignoreMap":383},[1532,1548,1572,1596,1603,1657,1694,1780,1809,1861,1868,1875,1972,2059,2122,2195,2242,2259,2307,2348,2364,2388,2397,2421,2473,2481],{"type":40,"tag":389,"props":1533,"children":1534},{"class":391,"line":27},[1535,1539,1544],{"type":40,"tag":389,"props":1536,"children":1537},{"style":622},[1538],{"type":46,"value":1112},{"type":40,"tag":389,"props":1540,"children":1541},{"style":1115},[1542],{"type":46,"value":1543}," HybridLogicalClock",{"type":40,"tag":389,"props":1545,"children":1546},{"style":411},[1547],{"type":46,"value":1123},{"type":40,"tag":389,"props":1549,"children":1550},{"class":391,"line":401},[1551,1555,1560,1564,1568],{"type":40,"tag":389,"props":1552,"children":1553},{"style":622},[1554],{"type":46,"value":1131},{"type":40,"tag":389,"props":1556,"children":1557},{"style":453},[1558],{"type":46,"value":1559}," physicalTime",{"type":40,"tag":389,"props":1561,"children":1562},{"style":411},[1563],{"type":46,"value":1141},{"type":40,"tag":389,"props":1565,"children":1566},{"style":815},[1567],{"type":46,"value":1146},{"type":40,"tag":389,"props":1569,"children":1570},{"style":411},[1571],{"type":46,"value":505},{"type":40,"tag":389,"props":1573,"children":1574},{"class":391,"line":23},[1575,1579,1584,1588,1592],{"type":40,"tag":389,"props":1576,"children":1577},{"style":622},[1578],{"type":46,"value":1131},{"type":40,"tag":389,"props":1580,"children":1581},{"style":453},[1582],{"type":46,"value":1583}," logical",{"type":40,"tag":389,"props":1585,"children":1586},{"style":411},[1587],{"type":46,"value":1141},{"type":40,"tag":389,"props":1589,"children":1590},{"style":815},[1591],{"type":46,"value":1146},{"type":40,"tag":389,"props":1593,"children":1594},{"style":411},[1595],{"type":46,"value":505},{"type":40,"tag":389,"props":1597,"children":1598},{"class":391,"line":599},[1599],{"type":40,"tag":389,"props":1600,"children":1601},{"emptyLinePlaceholder":603},[1602],{"type":46,"value":606},{"type":40,"tag":389,"props":1604,"children":1605},{"class":391,"line":609},[1606,1611,1615,1619,1624,1628,1632,1636,1640,1644,1648,1653],{"type":40,"tag":389,"props":1607,"children":1608},{"style":453},[1609],{"type":46,"value":1610},"  now",{"type":40,"tag":389,"props":1612,"children":1613},{"style":411},[1614],{"type":46,"value":1163},{"type":40,"tag":389,"props":1616,"children":1617},{"style":411},[1618],{"type":46,"value":450},{"type":40,"tag":389,"props":1620,"children":1621},{"style":453},[1622],{"type":46,"value":1623}," wallMs",{"type":40,"tag":389,"props":1625,"children":1626},{"style":411},[1627],{"type":46,"value":461},{"type":40,"tag":389,"props":1629,"children":1630},{"style":1115},[1631],{"type":46,"value":1168},{"type":40,"tag":389,"props":1633,"children":1634},{"style":411},[1635],{"type":46,"value":591},{"type":40,"tag":389,"props":1637,"children":1638},{"style":453},[1639],{"type":46,"value":1583},{"type":40,"tag":389,"props":1641,"children":1642},{"style":411},[1643],{"type":46,"value":461},{"type":40,"tag":389,"props":1645,"children":1646},{"style":1115},[1647],{"type":46,"value":1168},{"type":40,"tag":389,"props":1649,"children":1650},{"style":411},[1651],{"type":46,"value":1652}," }",{"type":40,"tag":389,"props":1654,"children":1655},{"style":411},[1656],{"type":46,"value":1123},{"type":40,"tag":389,"props":1658,"children":1659},{"class":391,"line":618},[1660,1665,1670,1674,1678,1682,1686,1690],{"type":40,"tag":389,"props":1661,"children":1662},{"style":622},[1663],{"type":46,"value":1664},"    const",{"type":40,"tag":389,"props":1666,"children":1667},{"style":405},[1668],{"type":46,"value":1669}," pt",{"type":40,"tag":389,"props":1671,"children":1672},{"style":411},[1673],{"type":46,"value":1141},{"type":40,"tag":389,"props":1675,"children":1676},{"style":405},[1677],{"type":46,"value":471},{"type":40,"tag":389,"props":1679,"children":1680},{"style":411},[1681],{"type":46,"value":414},{"type":40,"tag":389,"props":1683,"children":1684},{"style":417},[1685],{"type":46,"value":574},{"type":40,"tag":389,"props":1687,"children":1688},{"style":453},[1689],{"type":46,"value":476},{"type":40,"tag":389,"props":1691,"children":1692},{"style":411},[1693],{"type":46,"value":505},{"type":40,"tag":389,"props":1695,"children":1696},{"class":391,"line":1329},[1697,1702,1707,1712,1717,1721,1726,1730,1735,1739,1743,1747,1751,1755,1759,1764,1768,1772,1776],{"type":40,"tag":389,"props":1698,"children":1699},{"style":511},[1700],{"type":46,"value":1701},"    if",{"type":40,"tag":389,"props":1703,"children":1704},{"style":453},[1705],{"type":46,"value":1706}," (",{"type":40,"tag":389,"props":1708,"children":1709},{"style":405},[1710],{"type":46,"value":1711},"pt",{"type":40,"tag":389,"props":1713,"children":1714},{"style":411},[1715],{"type":46,"value":1716}," >",{"type":40,"tag":389,"props":1718,"children":1719},{"style":411},[1720],{"type":46,"value":1318},{"type":40,"tag":389,"props":1722,"children":1723},{"style":405},[1724],{"type":46,"value":1725},"physicalTime",{"type":40,"tag":389,"props":1727,"children":1728},{"style":453},[1729],{"type":46,"value":1292},{"type":40,"tag":389,"props":1731,"children":1732},{"style":411},[1733],{"type":46,"value":1734},"{",{"type":40,"tag":389,"props":1736,"children":1737},{"style":411},[1738],{"type":46,"value":1318},{"type":40,"tag":389,"props":1740,"children":1741},{"style":405},[1742],{"type":46,"value":1725},{"type":40,"tag":389,"props":1744,"children":1745},{"style":411},[1746],{"type":46,"value":1141},{"type":40,"tag":389,"props":1748,"children":1749},{"style":405},[1750],{"type":46,"value":1669},{"type":40,"tag":389,"props":1752,"children":1753},{"style":411},[1754],{"type":46,"value":591},{"type":40,"tag":389,"props":1756,"children":1757},{"style":411},[1758],{"type":46,"value":1318},{"type":40,"tag":389,"props":1760,"children":1761},{"style":405},[1762],{"type":46,"value":1763},"logical",{"type":40,"tag":389,"props":1765,"children":1766},{"style":411},[1767],{"type":46,"value":1141},{"type":40,"tag":389,"props":1769,"children":1770},{"style":815},[1771],{"type":46,"value":1146},{"type":40,"tag":389,"props":1773,"children":1774},{"style":411},[1775],{"type":46,"value":591},{"type":40,"tag":389,"props":1777,"children":1778},{"style":411},[1779],{"type":46,"value":1196},{"type":40,"tag":389,"props":1781,"children":1782},{"class":391,"line":1338},[1783,1788,1792,1796,1800,1805],{"type":40,"tag":389,"props":1784,"children":1785},{"style":511},[1786],{"type":46,"value":1787},"    else",{"type":40,"tag":389,"props":1789,"children":1790},{"style":411},[1791],{"type":46,"value":450},{"type":40,"tag":389,"props":1793,"children":1794},{"style":411},[1795],{"type":46,"value":1318},{"type":40,"tag":389,"props":1797,"children":1798},{"style":405},[1799],{"type":46,"value":1763},{"type":40,"tag":389,"props":1801,"children":1802},{"style":411},[1803],{"type":46,"value":1804},"++;",{"type":40,"tag":389,"props":1806,"children":1807},{"style":411},[1808],{"type":46,"value":1196},{"type":40,"tag":389,"props":1810,"children":1811},{"class":391,"line":1347},[1812,1816,1820,1824,1828,1832,1836,1840,1844,1848,1852,1856],{"type":40,"tag":389,"props":1813,"children":1814},{"style":511},[1815],{"type":46,"value":1313},{"type":40,"tag":389,"props":1817,"children":1818},{"style":411},[1819],{"type":46,"value":450},{"type":40,"tag":389,"props":1821,"children":1822},{"style":453},[1823],{"type":46,"value":1623},{"type":40,"tag":389,"props":1825,"children":1826},{"style":411},[1827],{"type":46,"value":461},{"type":40,"tag":389,"props":1829,"children":1830},{"style":411},[1831],{"type":46,"value":1318},{"type":40,"tag":389,"props":1833,"children":1834},{"style":405},[1835],{"type":46,"value":1725},{"type":40,"tag":389,"props":1837,"children":1838},{"style":411},[1839],{"type":46,"value":445},{"type":40,"tag":389,"props":1841,"children":1842},{"style":453},[1843],{"type":46,"value":1583},{"type":40,"tag":389,"props":1845,"children":1846},{"style":411},[1847],{"type":46,"value":461},{"type":40,"tag":389,"props":1849,"children":1850},{"style":411},[1851],{"type":46,"value":1318},{"type":40,"tag":389,"props":1853,"children":1854},{"style":405},[1855],{"type":46,"value":1763},{"type":40,"tag":389,"props":1857,"children":1858},{"style":411},[1859],{"type":46,"value":1860}," };\n",{"type":40,"tag":389,"props":1862,"children":1863},{"class":391,"line":1355},[1864],{"type":40,"tag":389,"props":1865,"children":1866},{"style":411},[1867],{"type":46,"value":1335},{"type":40,"tag":389,"props":1869,"children":1870},{"class":391,"line":1376},[1871],{"type":40,"tag":389,"props":1872,"children":1873},{"emptyLinePlaceholder":603},[1874],{"type":46,"value":606},{"type":40,"tag":389,"props":1876,"children":1877},{"class":391,"line":1408},[1878,1882,1886,1891,1895,1899,1903,1907,1911,1915,1919,1923,1927,1932,1936,1940,1944,1948,1952,1956,1960,1964,1968],{"type":40,"tag":389,"props":1879,"children":1880},{"style":453},[1881],{"type":46,"value":1204},{"type":40,"tag":389,"props":1883,"children":1884},{"style":411},[1885],{"type":46,"value":425},{"type":40,"tag":389,"props":1887,"children":1888},{"style":1211},[1889],{"type":46,"value":1890},"remote",{"type":40,"tag":389,"props":1892,"children":1893},{"style":411},[1894],{"type":46,"value":461},{"type":40,"tag":389,"props":1896,"children":1897},{"style":411},[1898],{"type":46,"value":450},{"type":40,"tag":389,"props":1900,"children":1901},{"style":453},[1902],{"type":46,"value":1623},{"type":40,"tag":389,"props":1904,"children":1905},{"style":411},[1906],{"type":46,"value":461},{"type":40,"tag":389,"props":1908,"children":1909},{"style":1115},[1910],{"type":46,"value":1168},{"type":40,"tag":389,"props":1912,"children":1913},{"style":411},[1914],{"type":46,"value":591},{"type":40,"tag":389,"props":1916,"children":1917},{"style":453},[1918],{"type":46,"value":1583},{"type":40,"tag":389,"props":1920,"children":1921},{"style":411},[1922],{"type":46,"value":461},{"type":40,"tag":389,"props":1924,"children":1925},{"style":1115},[1926],{"type":46,"value":1168},{"type":40,"tag":389,"props":1928,"children":1929},{"style":411},[1930],{"type":46,"value":1931}," }):",{"type":40,"tag":389,"props":1933,"children":1934},{"style":411},[1935],{"type":46,"value":450},{"type":40,"tag":389,"props":1937,"children":1938},{"style":453},[1939],{"type":46,"value":1623},{"type":40,"tag":389,"props":1941,"children":1942},{"style":411},[1943],{"type":46,"value":461},{"type":40,"tag":389,"props":1945,"children":1946},{"style":1115},[1947],{"type":46,"value":1168},{"type":40,"tag":389,"props":1949,"children":1950},{"style":411},[1951],{"type":46,"value":591},{"type":40,"tag":389,"props":1953,"children":1954},{"style":453},[1955],{"type":46,"value":1583},{"type":40,"tag":389,"props":1957,"children":1958},{"style":411},[1959],{"type":46,"value":461},{"type":40,"tag":389,"props":1961,"children":1962},{"style":1115},[1963],{"type":46,"value":1168},{"type":40,"tag":389,"props":1965,"children":1966},{"style":411},[1967],{"type":46,"value":1652},{"type":40,"tag":389,"props":1969,"children":1970},{"style":411},[1971],{"type":46,"value":1123},{"type":40,"tag":389,"props":1973,"children":1974},{"class":391,"line":1448},[1975,1979,1984,1988,1992,1996,2000,2004,2009,2013,2017,2021,2025,2029,2033,2037,2042,2046,2051,2055],{"type":40,"tag":389,"props":1976,"children":1977},{"style":622},[1978],{"type":46,"value":1664},{"type":40,"tag":389,"props":1980,"children":1981},{"style":405},[1982],{"type":46,"value":1983}," maxPt",{"type":40,"tag":389,"props":1985,"children":1986},{"style":411},[1987],{"type":46,"value":1141},{"type":40,"tag":389,"props":1989,"children":1990},{"style":405},[1991],{"type":46,"value":1256},{"type":40,"tag":389,"props":1993,"children":1994},{"style":411},[1995],{"type":46,"value":414},{"type":40,"tag":389,"props":1997,"children":1998},{"style":417},[1999],{"type":46,"value":1265},{"type":40,"tag":389,"props":2001,"children":2002},{"style":453},[2003],{"type":46,"value":425},{"type":40,"tag":389,"props":2005,"children":2006},{"style":405},[2007],{"type":46,"value":2008},"Date",{"type":40,"tag":389,"props":2010,"children":2011},{"style":411},[2012],{"type":46,"value":414},{"type":40,"tag":389,"props":2014,"children":2015},{"style":417},[2016],{"type":46,"value":574},{"type":40,"tag":389,"props":2018,"children":2019},{"style":453},[2020],{"type":46,"value":476},{"type":40,"tag":389,"props":2022,"children":2023},{"style":411},[2024],{"type":46,"value":445},{"type":40,"tag":389,"props":2026,"children":2027},{"style":411},[2028],{"type":46,"value":1318},{"type":40,"tag":389,"props":2030,"children":2031},{"style":405},[2032],{"type":46,"value":1725},{"type":40,"tag":389,"props":2034,"children":2035},{"style":411},[2036],{"type":46,"value":445},{"type":40,"tag":389,"props":2038,"children":2039},{"style":405},[2040],{"type":46,"value":2041}," remote",{"type":40,"tag":389,"props":2043,"children":2044},{"style":411},[2045],{"type":46,"value":414},{"type":40,"tag":389,"props":2047,"children":2048},{"style":405},[2049],{"type":46,"value":2050},"wallMs",{"type":40,"tag":389,"props":2052,"children":2053},{"style":453},[2054],{"type":46,"value":500},{"type":40,"tag":389,"props":2056,"children":2057},{"style":411},[2058],{"type":46,"value":505},{"type":40,"tag":389,"props":2060,"children":2061},{"class":391,"line":1494},[2062,2066,2070,2075,2080,2084,2088,2093,2097,2101,2105,2109,2113,2117],{"type":40,"tag":389,"props":2063,"children":2064},{"style":511},[2065],{"type":46,"value":1701},{"type":40,"tag":389,"props":2067,"children":2068},{"style":453},[2069],{"type":46,"value":1706},{"type":40,"tag":389,"props":2071,"children":2072},{"style":405},[2073],{"type":46,"value":2074},"maxPt",{"type":40,"tag":389,"props":2076,"children":2077},{"style":411},[2078],{"type":46,"value":2079}," ===",{"type":40,"tag":389,"props":2081,"children":2082},{"style":411},[2083],{"type":46,"value":1318},{"type":40,"tag":389,"props":2085,"children":2086},{"style":405},[2087],{"type":46,"value":1725},{"type":40,"tag":389,"props":2089,"children":2090},{"style":411},[2091],{"type":46,"value":2092}," &&",{"type":40,"tag":389,"props":2094,"children":2095},{"style":405},[2096],{"type":46,"value":1983},{"type":40,"tag":389,"props":2098,"children":2099},{"style":411},[2100],{"type":46,"value":2079},{"type":40,"tag":389,"props":2102,"children":2103},{"style":405},[2104],{"type":46,"value":2041},{"type":40,"tag":389,"props":2106,"children":2107},{"style":411},[2108],{"type":46,"value":414},{"type":40,"tag":389,"props":2110,"children":2111},{"style":405},[2112],{"type":46,"value":2050},{"type":40,"tag":389,"props":2114,"children":2115},{"style":453},[2116],{"type":46,"value":1292},{"type":40,"tag":389,"props":2118,"children":2119},{"style":411},[2120],{"type":46,"value":2121},"{\n",{"type":40,"tag":389,"props":2123,"children":2125},{"class":391,"line":2124},15,[2126,2131,2135,2139,2143,2147,2151,2155,2159,2163,2167,2171,2175,2179,2183,2187,2191],{"type":40,"tag":389,"props":2127,"children":2128},{"style":411},[2129],{"type":46,"value":2130},"      this.",{"type":40,"tag":389,"props":2132,"children":2133},{"style":405},[2134],{"type":46,"value":1763},{"type":40,"tag":389,"props":2136,"children":2137},{"style":411},[2138],{"type":46,"value":1141},{"type":40,"tag":389,"props":2140,"children":2141},{"style":405},[2142],{"type":46,"value":1256},{"type":40,"tag":389,"props":2144,"children":2145},{"style":411},[2146],{"type":46,"value":414},{"type":40,"tag":389,"props":2148,"children":2149},{"style":417},[2150],{"type":46,"value":1265},{"type":40,"tag":389,"props":2152,"children":2153},{"style":453},[2154],{"type":46,"value":425},{"type":40,"tag":389,"props":2156,"children":2157},{"style":411},[2158],{"type":46,"value":1274},{"type":40,"tag":389,"props":2160,"children":2161},{"style":405},[2162],{"type":46,"value":1763},{"type":40,"tag":389,"props":2164,"children":2165},{"style":411},[2166],{"type":46,"value":445},{"type":40,"tag":389,"props":2168,"children":2169},{"style":405},[2170],{"type":46,"value":2041},{"type":40,"tag":389,"props":2172,"children":2173},{"style":411},[2174],{"type":46,"value":414},{"type":40,"tag":389,"props":2176,"children":2177},{"style":405},[2178],{"type":46,"value":1763},{"type":40,"tag":389,"props":2180,"children":2181},{"style":453},[2182],{"type":46,"value":1292},{"type":40,"tag":389,"props":2184,"children":2185},{"style":411},[2186],{"type":46,"value":938},{"type":40,"tag":389,"props":2188,"children":2189},{"style":815},[2190],{"type":46,"value":1301},{"type":40,"tag":389,"props":2192,"children":2193},{"style":411},[2194],{"type":46,"value":505},{"type":40,"tag":389,"props":2196,"children":2198},{"class":391,"line":2197},16,[2199,2204,2209,2214,2218,2222,2226,2230,2234,2238],{"type":40,"tag":389,"props":2200,"children":2201},{"style":411},[2202],{"type":46,"value":2203},"    }",{"type":40,"tag":389,"props":2205,"children":2206},{"style":511},[2207],{"type":46,"value":2208}," else",{"type":40,"tag":389,"props":2210,"children":2211},{"style":511},[2212],{"type":46,"value":2213}," if",{"type":40,"tag":389,"props":2215,"children":2216},{"style":453},[2217],{"type":46,"value":1706},{"type":40,"tag":389,"props":2219,"children":2220},{"style":405},[2221],{"type":46,"value":2074},{"type":40,"tag":389,"props":2223,"children":2224},{"style":411},[2225],{"type":46,"value":2079},{"type":40,"tag":389,"props":2227,"children":2228},{"style":411},[2229],{"type":46,"value":1318},{"type":40,"tag":389,"props":2231,"children":2232},{"style":405},[2233],{"type":46,"value":1725},{"type":40,"tag":389,"props":2235,"children":2236},{"style":453},[2237],{"type":46,"value":1292},{"type":40,"tag":389,"props":2239,"children":2240},{"style":411},[2241],{"type":46,"value":2121},{"type":40,"tag":389,"props":2243,"children":2245},{"class":391,"line":2244},17,[2246,2250,2254],{"type":40,"tag":389,"props":2247,"children":2248},{"style":411},[2249],{"type":46,"value":2130},{"type":40,"tag":389,"props":2251,"children":2252},{"style":405},[2253],{"type":46,"value":1763},{"type":40,"tag":389,"props":2255,"children":2256},{"style":411},[2257],{"type":46,"value":2258},"++;\n",{"type":40,"tag":389,"props":2260,"children":2262},{"class":391,"line":2261},18,[2263,2267,2271,2275,2279,2283,2287,2291,2295,2299,2303],{"type":40,"tag":389,"props":2264,"children":2265},{"style":411},[2266],{"type":46,"value":2203},{"type":40,"tag":389,"props":2268,"children":2269},{"style":511},[2270],{"type":46,"value":2208},{"type":40,"tag":389,"props":2272,"children":2273},{"style":511},[2274],{"type":46,"value":2213},{"type":40,"tag":389,"props":2276,"children":2277},{"style":453},[2278],{"type":46,"value":1706},{"type":40,"tag":389,"props":2280,"children":2281},{"style":405},[2282],{"type":46,"value":2074},{"type":40,"tag":389,"props":2284,"children":2285},{"style":411},[2286],{"type":46,"value":2079},{"type":40,"tag":389,"props":2288,"children":2289},{"style":405},[2290],{"type":46,"value":2041},{"type":40,"tag":389,"props":2292,"children":2293},{"style":411},[2294],{"type":46,"value":414},{"type":40,"tag":389,"props":2296,"children":2297},{"style":405},[2298],{"type":46,"value":2050},{"type":40,"tag":389,"props":2300,"children":2301},{"style":453},[2302],{"type":46,"value":1292},{"type":40,"tag":389,"props":2304,"children":2305},{"style":411},[2306],{"type":46,"value":2121},{"type":40,"tag":389,"props":2308,"children":2310},{"class":391,"line":2309},19,[2311,2315,2319,2323,2327,2331,2335,2340,2344],{"type":40,"tag":389,"props":2312,"children":2313},{"style":411},[2314],{"type":46,"value":2130},{"type":40,"tag":389,"props":2316,"children":2317},{"style":405},[2318],{"type":46,"value":1763},{"type":40,"tag":389,"props":2320,"children":2321},{"style":411},[2322],{"type":46,"value":1141},{"type":40,"tag":389,"props":2324,"children":2325},{"style":405},[2326],{"type":46,"value":2041},{"type":40,"tag":389,"props":2328,"children":2329},{"style":411},[2330],{"type":46,"value":414},{"type":40,"tag":389,"props":2332,"children":2333},{"style":405},[2334],{"type":46,"value":1763},{"type":40,"tag":389,"props":2336,"children":2337},{"style":411},[2338],{"type":46,"value":2339}," +",{"type":40,"tag":389,"props":2341,"children":2342},{"style":815},[2343],{"type":46,"value":1301},{"type":40,"tag":389,"props":2345,"children":2346},{"style":411},[2347],{"type":46,"value":505},{"type":40,"tag":389,"props":2349,"children":2351},{"class":391,"line":2350},20,[2352,2356,2360],{"type":40,"tag":389,"props":2353,"children":2354},{"style":411},[2355],{"type":46,"value":2203},{"type":40,"tag":389,"props":2357,"children":2358},{"style":511},[2359],{"type":46,"value":2208},{"type":40,"tag":389,"props":2361,"children":2362},{"style":411},[2363],{"type":46,"value":1123},{"type":40,"tag":389,"props":2365,"children":2367},{"class":391,"line":2366},21,[2368,2372,2376,2380,2384],{"type":40,"tag":389,"props":2369,"children":2370},{"style":411},[2371],{"type":46,"value":2130},{"type":40,"tag":389,"props":2373,"children":2374},{"style":405},[2375],{"type":46,"value":1763},{"type":40,"tag":389,"props":2377,"children":2378},{"style":411},[2379],{"type":46,"value":1141},{"type":40,"tag":389,"props":2381,"children":2382},{"style":815},[2383],{"type":46,"value":1146},{"type":40,"tag":389,"props":2385,"children":2386},{"style":411},[2387],{"type":46,"value":505},{"type":40,"tag":389,"props":2389,"children":2391},{"class":391,"line":2390},22,[2392],{"type":40,"tag":389,"props":2393,"children":2394},{"style":411},[2395],{"type":46,"value":2396},"    }\n",{"type":40,"tag":389,"props":2398,"children":2400},{"class":391,"line":2399},23,[2401,2405,2409,2413,2417],{"type":40,"tag":389,"props":2402,"children":2403},{"style":411},[2404],{"type":46,"value":1243},{"type":40,"tag":389,"props":2406,"children":2407},{"style":405},[2408],{"type":46,"value":1725},{"type":40,"tag":389,"props":2410,"children":2411},{"style":411},[2412],{"type":46,"value":1141},{"type":40,"tag":389,"props":2414,"children":2415},{"style":405},[2416],{"type":46,"value":1983},{"type":40,"tag":389,"props":2418,"children":2419},{"style":411},[2420],{"type":46,"value":505},{"type":40,"tag":389,"props":2422,"children":2424},{"class":391,"line":2423},24,[2425,2429,2433,2437,2441,2445,2449,2453,2457,2461,2465,2469],{"type":40,"tag":389,"props":2426,"children":2427},{"style":511},[2428],{"type":46,"value":1313},{"type":40,"tag":389,"props":2430,"children":2431},{"style":411},[2432],{"type":46,"value":450},{"type":40,"tag":389,"props":2434,"children":2435},{"style":453},[2436],{"type":46,"value":1623},{"type":40,"tag":389,"props":2438,"children":2439},{"style":411},[2440],{"type":46,"value":461},{"type":40,"tag":389,"props":2442,"children":2443},{"style":411},[2444],{"type":46,"value":1318},{"type":40,"tag":389,"props":2446,"children":2447},{"style":405},[2448],{"type":46,"value":1725},{"type":40,"tag":389,"props":2450,"children":2451},{"style":411},[2452],{"type":46,"value":445},{"type":40,"tag":389,"props":2454,"children":2455},{"style":453},[2456],{"type":46,"value":1583},{"type":40,"tag":389,"props":2458,"children":2459},{"style":411},[2460],{"type":46,"value":461},{"type":40,"tag":389,"props":2462,"children":2463},{"style":411},[2464],{"type":46,"value":1318},{"type":40,"tag":389,"props":2466,"children":2467},{"style":405},[2468],{"type":46,"value":1763},{"type":40,"tag":389,"props":2470,"children":2471},{"style":411},[2472],{"type":46,"value":1860},{"type":40,"tag":389,"props":2474,"children":2476},{"class":391,"line":2475},25,[2477],{"type":40,"tag":389,"props":2478,"children":2479},{"style":411},[2480],{"type":46,"value":1335},{"type":40,"tag":389,"props":2482,"children":2484},{"class":391,"line":2483},26,[2485],{"type":40,"tag":389,"props":2486,"children":2487},{"style":411},[2488],{"type":46,"value":1344},{"type":40,"tag":664,"props":2490,"children":2492},{"id":2491},"fencing-tokens-for-distributed-locks",[2493],{"type":46,"value":2494},"Fencing tokens for distributed locks",{"type":40,"tag":49,"props":2496,"children":2497},{},[2498],{"type":46,"value":2499},"Don't rely on clock-based expiry alone. Hand out a monotonically increasing token at acquisition; the protected resource rejects stale ones.",{"type":40,"tag":378,"props":2501,"children":2503},{"className":380,"code":2502,"language":382,"meta":383,"style":383},"const { token } = await acquireLockWithToken(\"resource-123\"); \u002F\u002F token monotonically increases\nawait protectedService.write({ data: newData, fencingToken: token });\n\n\u002F\u002F The protected service is the final arbiter, not the clock\nasync function write(req: { data: Data; fencingToken: number }) {\n  if (req.fencingToken \u003C= this.lastSeenToken) {\n    throw new Error(\"Stale fencing token -- lock was superseded\");\n  }\n  this.lastSeenToken = req.fencingToken;\n  await db.save(req.data);\n}\n",[2504],{"type":40,"tag":55,"props":2505,"children":2506},{"__ignoreMap":383},[2507,2571,2643,2650,2658,2731,2778,2820,2827,2860,2907],{"type":40,"tag":389,"props":2508,"children":2509},{"class":391,"line":27},[2510,2514,2518,2523,2527,2531,2536,2541,2545,2549,2554,2558,2562,2566],{"type":40,"tag":389,"props":2511,"children":2512},{"style":622},[2513],{"type":46,"value":625},{"type":40,"tag":389,"props":2515,"children":2516},{"style":411},[2517],{"type":46,"value":450},{"type":40,"tag":389,"props":2519,"children":2520},{"style":405},[2521],{"type":46,"value":2522}," token ",{"type":40,"tag":389,"props":2524,"children":2525},{"style":411},[2526],{"type":46,"value":495},{"type":40,"tag":389,"props":2528,"children":2529},{"style":411},[2530],{"type":46,"value":1141},{"type":40,"tag":389,"props":2532,"children":2533},{"style":511},[2534],{"type":46,"value":2535}," await",{"type":40,"tag":389,"props":2537,"children":2538},{"style":417},[2539],{"type":46,"value":2540}," acquireLockWithToken",{"type":40,"tag":389,"props":2542,"children":2543},{"style":405},[2544],{"type":46,"value":425},{"type":40,"tag":389,"props":2546,"children":2547},{"style":411},[2548],{"type":46,"value":430},{"type":40,"tag":389,"props":2550,"children":2551},{"style":433},[2552],{"type":46,"value":2553},"resource-123",{"type":40,"tag":389,"props":2555,"children":2556},{"style":411},[2557],{"type":46,"value":430},{"type":40,"tag":389,"props":2559,"children":2560},{"style":405},[2561],{"type":46,"value":500},{"type":40,"tag":389,"props":2563,"children":2564},{"style":411},[2565],{"type":46,"value":591},{"type":40,"tag":389,"props":2567,"children":2568},{"style":395},[2569],{"type":46,"value":2570}," \u002F\u002F token monotonically increases\n",{"type":40,"tag":389,"props":2572,"children":2573},{"class":391,"line":401},[2574,2578,2583,2587,2592,2596,2600,2605,2609,2614,2618,2623,2627,2631,2635,2639],{"type":40,"tag":389,"props":2575,"children":2576},{"style":511},[2577],{"type":46,"value":514},{"type":40,"tag":389,"props":2579,"children":2580},{"style":405},[2581],{"type":46,"value":2582}," protectedService",{"type":40,"tag":389,"props":2584,"children":2585},{"style":411},[2586],{"type":46,"value":414},{"type":40,"tag":389,"props":2588,"children":2589},{"style":417},[2590],{"type":46,"value":2591},"write",{"type":40,"tag":389,"props":2593,"children":2594},{"style":405},[2595],{"type":46,"value":425},{"type":40,"tag":389,"props":2597,"children":2598},{"style":411},[2599],{"type":46,"value":1734},{"type":40,"tag":389,"props":2601,"children":2602},{"style":453},[2603],{"type":46,"value":2604}," data",{"type":40,"tag":389,"props":2606,"children":2607},{"style":411},[2608],{"type":46,"value":461},{"type":40,"tag":389,"props":2610,"children":2611},{"style":405},[2612],{"type":46,"value":2613}," newData",{"type":40,"tag":389,"props":2615,"children":2616},{"style":411},[2617],{"type":46,"value":445},{"type":40,"tag":389,"props":2619,"children":2620},{"style":453},[2621],{"type":46,"value":2622}," fencingToken",{"type":40,"tag":389,"props":2624,"children":2625},{"style":411},[2626],{"type":46,"value":461},{"type":40,"tag":389,"props":2628,"children":2629},{"style":405},[2630],{"type":46,"value":2522},{"type":40,"tag":389,"props":2632,"children":2633},{"style":411},[2634],{"type":46,"value":495},{"type":40,"tag":389,"props":2636,"children":2637},{"style":405},[2638],{"type":46,"value":500},{"type":40,"tag":389,"props":2640,"children":2641},{"style":411},[2642],{"type":46,"value":505},{"type":40,"tag":389,"props":2644,"children":2645},{"class":391,"line":23},[2646],{"type":40,"tag":389,"props":2647,"children":2648},{"emptyLinePlaceholder":603},[2649],{"type":46,"value":606},{"type":40,"tag":389,"props":2651,"children":2652},{"class":391,"line":599},[2653],{"type":40,"tag":389,"props":2654,"children":2655},{"style":395},[2656],{"type":46,"value":2657},"\u002F\u002F The protected service is the final arbiter, not the clock\n",{"type":40,"tag":389,"props":2659,"children":2660},{"class":391,"line":609},[2661,2666,2671,2676,2680,2685,2689,2693,2697,2701,2706,2710,2714,2718,2722,2727],{"type":40,"tag":389,"props":2662,"children":2663},{"style":622},[2664],{"type":46,"value":2665},"async",{"type":40,"tag":389,"props":2667,"children":2668},{"style":622},[2669],{"type":46,"value":2670}," function",{"type":40,"tag":389,"props":2672,"children":2673},{"style":417},[2674],{"type":46,"value":2675}," write",{"type":40,"tag":389,"props":2677,"children":2678},{"style":411},[2679],{"type":46,"value":425},{"type":40,"tag":389,"props":2681,"children":2682},{"style":1211},[2683],{"type":46,"value":2684},"req",{"type":40,"tag":389,"props":2686,"children":2687},{"style":411},[2688],{"type":46,"value":461},{"type":40,"tag":389,"props":2690,"children":2691},{"style":411},[2692],{"type":46,"value":450},{"type":40,"tag":389,"props":2694,"children":2695},{"style":453},[2696],{"type":46,"value":2604},{"type":40,"tag":389,"props":2698,"children":2699},{"style":411},[2700],{"type":46,"value":461},{"type":40,"tag":389,"props":2702,"children":2703},{"style":1115},[2704],{"type":46,"value":2705}," Data",{"type":40,"tag":389,"props":2707,"children":2708},{"style":411},[2709],{"type":46,"value":591},{"type":40,"tag":389,"props":2711,"children":2712},{"style":453},[2713],{"type":46,"value":2622},{"type":40,"tag":389,"props":2715,"children":2716},{"style":411},[2717],{"type":46,"value":461},{"type":40,"tag":389,"props":2719,"children":2720},{"style":1115},[2721],{"type":46,"value":1168},{"type":40,"tag":389,"props":2723,"children":2724},{"style":411},[2725],{"type":46,"value":2726}," })",{"type":40,"tag":389,"props":2728,"children":2729},{"style":411},[2730],{"type":46,"value":1123},{"type":40,"tag":389,"props":2732,"children":2733},{"class":391,"line":618},[2734,2739,2743,2747,2751,2756,2761,2765,2770,2774],{"type":40,"tag":389,"props":2735,"children":2736},{"style":511},[2737],{"type":46,"value":2738},"  if",{"type":40,"tag":389,"props":2740,"children":2741},{"style":453},[2742],{"type":46,"value":1706},{"type":40,"tag":389,"props":2744,"children":2745},{"style":405},[2746],{"type":46,"value":2684},{"type":40,"tag":389,"props":2748,"children":2749},{"style":411},[2750],{"type":46,"value":414},{"type":40,"tag":389,"props":2752,"children":2753},{"style":405},[2754],{"type":46,"value":2755},"fencingToken",{"type":40,"tag":389,"props":2757,"children":2758},{"style":411},[2759],{"type":46,"value":2760}," \u003C=",{"type":40,"tag":389,"props":2762,"children":2763},{"style":411},[2764],{"type":46,"value":1318},{"type":40,"tag":389,"props":2766,"children":2767},{"style":405},[2768],{"type":46,"value":2769},"lastSeenToken",{"type":40,"tag":389,"props":2771,"children":2772},{"style":453},[2773],{"type":46,"value":1292},{"type":40,"tag":389,"props":2775,"children":2776},{"style":411},[2777],{"type":46,"value":2121},{"type":40,"tag":389,"props":2779,"children":2780},{"class":391,"line":1329},[2781,2786,2790,2795,2799,2803,2808,2812,2816],{"type":40,"tag":389,"props":2782,"children":2783},{"style":511},[2784],{"type":46,"value":2785},"    throw",{"type":40,"tag":389,"props":2787,"children":2788},{"style":411},[2789],{"type":46,"value":466},{"type":40,"tag":389,"props":2791,"children":2792},{"style":417},[2793],{"type":46,"value":2794}," Error",{"type":40,"tag":389,"props":2796,"children":2797},{"style":453},[2798],{"type":46,"value":425},{"type":40,"tag":389,"props":2800,"children":2801},{"style":411},[2802],{"type":46,"value":430},{"type":40,"tag":389,"props":2804,"children":2805},{"style":433},[2806],{"type":46,"value":2807},"Stale fencing token -- lock was superseded",{"type":40,"tag":389,"props":2809,"children":2810},{"style":411},[2811],{"type":46,"value":430},{"type":40,"tag":389,"props":2813,"children":2814},{"style":453},[2815],{"type":46,"value":500},{"type":40,"tag":389,"props":2817,"children":2818},{"style":411},[2819],{"type":46,"value":505},{"type":40,"tag":389,"props":2821,"children":2822},{"class":391,"line":1338},[2823],{"type":40,"tag":389,"props":2824,"children":2825},{"style":411},[2826],{"type":46,"value":1335},{"type":40,"tag":389,"props":2828,"children":2829},{"class":391,"line":1347},[2830,2835,2839,2843,2848,2852,2856],{"type":40,"tag":389,"props":2831,"children":2832},{"style":411},[2833],{"type":46,"value":2834},"  this.",{"type":40,"tag":389,"props":2836,"children":2837},{"style":405},[2838],{"type":46,"value":2769},{"type":40,"tag":389,"props":2840,"children":2841},{"style":411},[2842],{"type":46,"value":1141},{"type":40,"tag":389,"props":2844,"children":2845},{"style":405},[2846],{"type":46,"value":2847}," req",{"type":40,"tag":389,"props":2849,"children":2850},{"style":411},[2851],{"type":46,"value":414},{"type":40,"tag":389,"props":2853,"children":2854},{"style":405},[2855],{"type":46,"value":2755},{"type":40,"tag":389,"props":2857,"children":2858},{"style":411},[2859],{"type":46,"value":505},{"type":40,"tag":389,"props":2861,"children":2862},{"class":391,"line":1355},[2863,2868,2873,2877,2882,2886,2890,2894,2899,2903],{"type":40,"tag":389,"props":2864,"children":2865},{"style":511},[2866],{"type":46,"value":2867},"  await",{"type":40,"tag":389,"props":2869,"children":2870},{"style":405},[2871],{"type":46,"value":2872}," db",{"type":40,"tag":389,"props":2874,"children":2875},{"style":411},[2876],{"type":46,"value":414},{"type":40,"tag":389,"props":2878,"children":2879},{"style":417},[2880],{"type":46,"value":2881},"save",{"type":40,"tag":389,"props":2883,"children":2884},{"style":453},[2885],{"type":46,"value":425},{"type":40,"tag":389,"props":2887,"children":2888},{"style":405},[2889],{"type":46,"value":2684},{"type":40,"tag":389,"props":2891,"children":2892},{"style":411},[2893],{"type":46,"value":414},{"type":40,"tag":389,"props":2895,"children":2896},{"style":405},[2897],{"type":46,"value":2898},"data",{"type":40,"tag":389,"props":2900,"children":2901},{"style":453},[2902],{"type":46,"value":500},{"type":40,"tag":389,"props":2904,"children":2905},{"style":411},[2906],{"type":46,"value":505},{"type":40,"tag":389,"props":2908,"children":2909},{"class":391,"line":1376},[2910],{"type":40,"tag":389,"props":2911,"children":2912},{"style":411},[2913],{"type":46,"value":1344},{"type":40,"tag":49,"props":2915,"children":2916},{},[2917],{"type":46,"value":2918},"Even if skew makes two processes believe they hold the lock, only the highest token can write.",{"type":40,"tag":70,"props":2920,"children":2922},{"id":2921},"anti-patterns",[2923],{"type":46,"value":2924},"Anti-Patterns",{"type":40,"tag":378,"props":2926,"children":2928},{"className":380,"code":2927,"language":382,"meta":383,"style":383},"\u002F\u002F Duration with wall clock: can be negative\nconst elapsed = Date.now() - start; \u002F\u002F Use process.hrtime.bigint() instead\n\n\u002F\u002F Cross-machine ordering with wall clock: undefined within skew window\nevents.sort((a, b) => a.timestamp - b.timestamp); \u002F\u002F Timestamps from different machines\n\n\u002F\u002F Absolute expiry across machines: skew causes early\u002Flate expiry\nawait cache.set(key, { expiresAt: Date.now() + 60000 }); \u002F\u002F Pass ttlSeconds instead\n\n\u002F\u002F Last-write-wins with wall clock: \"last\" is undefined\nconst winner = writes.reduce((a, b) => a.timestamp > b.timestamp ? a : b);\n\n\u002F\u002F Lock expiry with wall clock: two holders possible\nif (Date.now() > lockExpiresAt) acquireLock(); \u002F\u002F Different machine's clock\n",[2929],{"type":40,"tag":55,"props":2930,"children":2931},{"__ignoreMap":383},[2932,2940,2990,2997,3005,3093,3100,3108,3192,3199,3207,3317,3324,3332],{"type":40,"tag":389,"props":2933,"children":2934},{"class":391,"line":27},[2935],{"type":40,"tag":389,"props":2936,"children":2937},{"style":395},[2938],{"type":46,"value":2939},"\u002F\u002F Duration with wall clock: can be negative\n",{"type":40,"tag":389,"props":2941,"children":2942},{"class":391,"line":401},[2943,2947,2952,2956,2960,2964,2968,2972,2976,2981,2985],{"type":40,"tag":389,"props":2944,"children":2945},{"style":622},[2946],{"type":46,"value":625},{"type":40,"tag":389,"props":2948,"children":2949},{"style":405},[2950],{"type":46,"value":2951}," elapsed ",{"type":40,"tag":389,"props":2953,"children":2954},{"style":411},[2955],{"type":46,"value":635},{"type":40,"tag":389,"props":2957,"children":2958},{"style":405},[2959],{"type":46,"value":471},{"type":40,"tag":389,"props":2961,"children":2962},{"style":411},[2963],{"type":46,"value":414},{"type":40,"tag":389,"props":2965,"children":2966},{"style":417},[2967],{"type":46,"value":574},{"type":40,"tag":389,"props":2969,"children":2970},{"style":405},[2971],{"type":46,"value":490},{"type":40,"tag":389,"props":2973,"children":2974},{"style":411},[2975],{"type":46,"value":802},{"type":40,"tag":389,"props":2977,"children":2978},{"style":405},[2979],{"type":46,"value":2980}," start",{"type":40,"tag":389,"props":2982,"children":2983},{"style":411},[2984],{"type":46,"value":591},{"type":40,"tag":389,"props":2986,"children":2987},{"style":395},[2988],{"type":46,"value":2989}," \u002F\u002F Use process.hrtime.bigint() instead\n",{"type":40,"tag":389,"props":2991,"children":2992},{"class":391,"line":23},[2993],{"type":40,"tag":389,"props":2994,"children":2995},{"emptyLinePlaceholder":603},[2996],{"type":46,"value":606},{"type":40,"tag":389,"props":2998,"children":2999},{"class":391,"line":599},[3000],{"type":40,"tag":389,"props":3001,"children":3002},{"style":395},[3003],{"type":46,"value":3004},"\u002F\u002F Cross-machine ordering with wall clock: undefined within skew window\n",{"type":40,"tag":389,"props":3006,"children":3007},{"class":391,"line":609},[3008,3013,3017,3022,3026,3030,3035,3039,3044,3048,3053,3058,3062,3067,3071,3075,3079,3084,3088],{"type":40,"tag":389,"props":3009,"children":3010},{"style":405},[3011],{"type":46,"value":3012},"events",{"type":40,"tag":389,"props":3014,"children":3015},{"style":411},[3016],{"type":46,"value":414},{"type":40,"tag":389,"props":3018,"children":3019},{"style":417},[3020],{"type":46,"value":3021},"sort",{"type":40,"tag":389,"props":3023,"children":3024},{"style":405},[3025],{"type":46,"value":425},{"type":40,"tag":389,"props":3027,"children":3028},{"style":411},[3029],{"type":46,"value":425},{"type":40,"tag":389,"props":3031,"children":3032},{"style":1211},[3033],{"type":46,"value":3034},"a",{"type":40,"tag":389,"props":3036,"children":3037},{"style":411},[3038],{"type":46,"value":445},{"type":40,"tag":389,"props":3040,"children":3041},{"style":1211},[3042],{"type":46,"value":3043}," b",{"type":40,"tag":389,"props":3045,"children":3046},{"style":411},[3047],{"type":46,"value":500},{"type":40,"tag":389,"props":3049,"children":3050},{"style":622},[3051],{"type":46,"value":3052}," =>",{"type":40,"tag":389,"props":3054,"children":3055},{"style":405},[3056],{"type":46,"value":3057}," a",{"type":40,"tag":389,"props":3059,"children":3060},{"style":411},[3061],{"type":46,"value":414},{"type":40,"tag":389,"props":3063,"children":3064},{"style":405},[3065],{"type":46,"value":3066},"timestamp ",{"type":40,"tag":389,"props":3068,"children":3069},{"style":411},[3070],{"type":46,"value":802},{"type":40,"tag":389,"props":3072,"children":3073},{"style":405},[3074],{"type":46,"value":3043},{"type":40,"tag":389,"props":3076,"children":3077},{"style":411},[3078],{"type":46,"value":414},{"type":40,"tag":389,"props":3080,"children":3081},{"style":405},[3082],{"type":46,"value":3083},"timestamp)",{"type":40,"tag":389,"props":3085,"children":3086},{"style":411},[3087],{"type":46,"value":591},{"type":40,"tag":389,"props":3089,"children":3090},{"style":395},[3091],{"type":46,"value":3092}," \u002F\u002F Timestamps from different machines\n",{"type":40,"tag":389,"props":3094,"children":3095},{"class":391,"line":618},[3096],{"type":40,"tag":389,"props":3097,"children":3098},{"emptyLinePlaceholder":603},[3099],{"type":46,"value":606},{"type":40,"tag":389,"props":3101,"children":3102},{"class":391,"line":1329},[3103],{"type":40,"tag":389,"props":3104,"children":3105},{"style":395},[3106],{"type":46,"value":3107},"\u002F\u002F Absolute expiry across machines: skew causes early\u002Flate expiry\n",{"type":40,"tag":389,"props":3109,"children":3110},{"class":391,"line":1338},[3111,3115,3120,3124,3129,3133,3137,3141,3146,3150,3154,3158,3162,3166,3170,3175,3179,3183,3187],{"type":40,"tag":389,"props":3112,"children":3113},{"style":511},[3114],{"type":46,"value":514},{"type":40,"tag":389,"props":3116,"children":3117},{"style":405},[3118],{"type":46,"value":3119}," cache",{"type":40,"tag":389,"props":3121,"children":3122},{"style":411},[3123],{"type":46,"value":414},{"type":40,"tag":389,"props":3125,"children":3126},{"style":417},[3127],{"type":46,"value":3128},"set",{"type":40,"tag":389,"props":3130,"children":3131},{"style":405},[3132],{"type":46,"value":1054},{"type":40,"tag":389,"props":3134,"children":3135},{"style":411},[3136],{"type":46,"value":445},{"type":40,"tag":389,"props":3138,"children":3139},{"style":411},[3140],{"type":46,"value":450},{"type":40,"tag":389,"props":3142,"children":3143},{"style":453},[3144],{"type":46,"value":3145}," expiresAt",{"type":40,"tag":389,"props":3147,"children":3148},{"style":411},[3149],{"type":46,"value":461},{"type":40,"tag":389,"props":3151,"children":3152},{"style":405},[3153],{"type":46,"value":471},{"type":40,"tag":389,"props":3155,"children":3156},{"style":411},[3157],{"type":46,"value":414},{"type":40,"tag":389,"props":3159,"children":3160},{"style":417},[3161],{"type":46,"value":574},{"type":40,"tag":389,"props":3163,"children":3164},{"style":405},[3165],{"type":46,"value":490},{"type":40,"tag":389,"props":3167,"children":3168},{"style":411},[3169],{"type":46,"value":938},{"type":40,"tag":389,"props":3171,"children":3172},{"style":815},[3173],{"type":46,"value":3174}," 60000",{"type":40,"tag":389,"props":3176,"children":3177},{"style":411},[3178],{"type":46,"value":1652},{"type":40,"tag":389,"props":3180,"children":3181},{"style":405},[3182],{"type":46,"value":500},{"type":40,"tag":389,"props":3184,"children":3185},{"style":411},[3186],{"type":46,"value":591},{"type":40,"tag":389,"props":3188,"children":3189},{"style":395},[3190],{"type":46,"value":3191}," \u002F\u002F Pass ttlSeconds instead\n",{"type":40,"tag":389,"props":3193,"children":3194},{"class":391,"line":1347},[3195],{"type":40,"tag":389,"props":3196,"children":3197},{"emptyLinePlaceholder":603},[3198],{"type":46,"value":606},{"type":40,"tag":389,"props":3200,"children":3201},{"class":391,"line":1355},[3202],{"type":40,"tag":389,"props":3203,"children":3204},{"style":395},[3205],{"type":46,"value":3206},"\u002F\u002F Last-write-wins with wall clock: \"last\" is undefined\n",{"type":40,"tag":389,"props":3208,"children":3209},{"class":391,"line":1376},[3210,3214,3219,3223,3228,3232,3237,3241,3245,3249,3253,3257,3261,3265,3269,3273,3277,3282,3286,3290,3294,3299,3304,3308,3313],{"type":40,"tag":389,"props":3211,"children":3212},{"style":622},[3213],{"type":46,"value":625},{"type":40,"tag":389,"props":3215,"children":3216},{"style":405},[3217],{"type":46,"value":3218}," winner ",{"type":40,"tag":389,"props":3220,"children":3221},{"style":411},[3222],{"type":46,"value":635},{"type":40,"tag":389,"props":3224,"children":3225},{"style":405},[3226],{"type":46,"value":3227}," writes",{"type":40,"tag":389,"props":3229,"children":3230},{"style":411},[3231],{"type":46,"value":414},{"type":40,"tag":389,"props":3233,"children":3234},{"style":417},[3235],{"type":46,"value":3236},"reduce",{"type":40,"tag":389,"props":3238,"children":3239},{"style":405},[3240],{"type":46,"value":425},{"type":40,"tag":389,"props":3242,"children":3243},{"style":411},[3244],{"type":46,"value":425},{"type":40,"tag":389,"props":3246,"children":3247},{"style":1211},[3248],{"type":46,"value":3034},{"type":40,"tag":389,"props":3250,"children":3251},{"style":411},[3252],{"type":46,"value":445},{"type":40,"tag":389,"props":3254,"children":3255},{"style":1211},[3256],{"type":46,"value":3043},{"type":40,"tag":389,"props":3258,"children":3259},{"style":411},[3260],{"type":46,"value":500},{"type":40,"tag":389,"props":3262,"children":3263},{"style":622},[3264],{"type":46,"value":3052},{"type":40,"tag":389,"props":3266,"children":3267},{"style":405},[3268],{"type":46,"value":3057},{"type":40,"tag":389,"props":3270,"children":3271},{"style":411},[3272],{"type":46,"value":414},{"type":40,"tag":389,"props":3274,"children":3275},{"style":405},[3276],{"type":46,"value":3066},{"type":40,"tag":389,"props":3278,"children":3279},{"style":411},[3280],{"type":46,"value":3281},">",{"type":40,"tag":389,"props":3283,"children":3284},{"style":405},[3285],{"type":46,"value":3043},{"type":40,"tag":389,"props":3287,"children":3288},{"style":411},[3289],{"type":46,"value":414},{"type":40,"tag":389,"props":3291,"children":3292},{"style":405},[3293],{"type":46,"value":3066},{"type":40,"tag":389,"props":3295,"children":3296},{"style":411},[3297],{"type":46,"value":3298},"?",{"type":40,"tag":389,"props":3300,"children":3301},{"style":405},[3302],{"type":46,"value":3303}," a ",{"type":40,"tag":389,"props":3305,"children":3306},{"style":411},[3307],{"type":46,"value":461},{"type":40,"tag":389,"props":3309,"children":3310},{"style":405},[3311],{"type":46,"value":3312}," b)",{"type":40,"tag":389,"props":3314,"children":3315},{"style":411},[3316],{"type":46,"value":505},{"type":40,"tag":389,"props":3318,"children":3319},{"class":391,"line":1408},[3320],{"type":40,"tag":389,"props":3321,"children":3322},{"emptyLinePlaceholder":603},[3323],{"type":46,"value":606},{"type":40,"tag":389,"props":3325,"children":3326},{"class":391,"line":1448},[3327],{"type":40,"tag":389,"props":3328,"children":3329},{"style":395},[3330],{"type":46,"value":3331},"\u002F\u002F Lock expiry with wall clock: two holders possible\n",{"type":40,"tag":389,"props":3333,"children":3334},{"class":391,"line":1494},[3335,3340,3345,3349,3353,3357,3361,3366,3371,3375,3379],{"type":40,"tag":389,"props":3336,"children":3337},{"style":511},[3338],{"type":46,"value":3339},"if",{"type":40,"tag":389,"props":3341,"children":3342},{"style":405},[3343],{"type":46,"value":3344}," (Date",{"type":40,"tag":389,"props":3346,"children":3347},{"style":411},[3348],{"type":46,"value":414},{"type":40,"tag":389,"props":3350,"children":3351},{"style":417},[3352],{"type":46,"value":574},{"type":40,"tag":389,"props":3354,"children":3355},{"style":405},[3356],{"type":46,"value":490},{"type":40,"tag":389,"props":3358,"children":3359},{"style":411},[3360],{"type":46,"value":3281},{"type":40,"tag":389,"props":3362,"children":3363},{"style":405},[3364],{"type":46,"value":3365}," lockExpiresAt) ",{"type":40,"tag":389,"props":3367,"children":3368},{"style":417},[3369],{"type":46,"value":3370},"acquireLock",{"type":40,"tag":389,"props":3372,"children":3373},{"style":405},[3374],{"type":46,"value":476},{"type":40,"tag":389,"props":3376,"children":3377},{"style":411},[3378],{"type":46,"value":591},{"type":40,"tag":389,"props":3380,"children":3381},{"style":395},[3382],{"type":46,"value":3383}," \u002F\u002F Different machine's clock\n",{"type":40,"tag":70,"props":3385,"children":3387},{"id":3386},"related-traps",[3388],{"type":46,"value":3389},"Related Traps",{"type":40,"tag":3391,"props":3392,"children":3393},"ul",{},[3394,3404,3414,3424],{"type":40,"tag":277,"props":3395,"children":3396},{},[3397,3402],{"type":40,"tag":64,"props":3398,"children":3399},{},[3400],{"type":46,"value":3401},"Race Conditions",{"type":46,"value":3403}," -- clock skew can create race conditions in distributed locks. Two processes both believe they hold an \"exclusive\" lock because their clocks disagree on whether the TTL has expired. Fencing tokens prevent the downstream corruption even when the lock fails.",{"type":40,"tag":277,"props":3405,"children":3406},{},[3407,3412],{"type":40,"tag":64,"props":3408,"children":3409},{},[3410],{"type":46,"value":3411},"Retry Storms",{"type":46,"value":3413}," -- timeout calculations using wall clock can fire early (clock jumps forward) or never fire (clock jumps backward). Use monotonic clocks for all timeout logic.",{"type":40,"tag":277,"props":3415,"children":3416},{},[3417,3422],{"type":40,"tag":64,"props":3418,"children":3419},{},[3420],{"type":46,"value":3421},"Hot Partitions",{"type":46,"value":3423}," -- time-based partition keys interact with clock skew at boundaries. Near midnight, machines with different clocks write to different date partitions, creating inconsistency.",{"type":40,"tag":277,"props":3425,"children":3426},{},[3427,3432],{"type":40,"tag":64,"props":3428,"children":3429},{},[3430],{"type":46,"value":3431},"Idempotency",{"type":46,"value":3433}," -- deduplication windows based on timestamps are unreliable when events come from machines with different clocks. Use unique IDs for deduplication, not timestamp proximity.",{"type":40,"tag":3435,"props":3436,"children":3437},"style",{},[3438],{"type":46,"value":3439},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":3441,"total":2483},[3442,3461,3474,3484,3501,3516,3530,3547,3560,3572,3583,3594],{"slug":3443,"name":3443,"fn":3444,"description":3445,"org":3446,"tags":3447,"stars":3458,"repoUrl":3459,"updatedAt":3460},"trigger-authoring-chat-agent","author durable AI chat agents with Trigger.dev","Author and run a durable AI chat agent with chat.agent from @trigger.dev\u002Fsdk\u002Fai: the per-turn run loop, why you MUST spread ...chat.toStreamTextOptions() first, returning a StreamTextResult vs calling chat.pipe(), the two server actions (chat.createStartSessionAction + auth.createPublicToken), and wiring useChat to useTriggerChatTransport. Load this when building, modifying, or debugging a chat backend (the agent task or its lifecycle hooks) or its React transport, when declaring typed tools or custom data parts, or when migrating a plain AI SDK streamText route to chat.agent.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3448,3451,3454,3455],{"name":3449,"slug":3450,"type":16},"Agents","agents",{"name":3452,"slug":3453,"type":16},"SDK","sdk",{"name":9,"slug":8,"type":16},{"name":3456,"slug":3457,"type":16},"Workflow Automation","workflow-automation",14401,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Ftrigger.dev","2026-07-02T17:12:52.307135",{"slug":3462,"name":3462,"fn":3463,"description":3464,"org":3465,"tags":3466,"stars":3458,"repoUrl":3459,"updatedAt":3473},"trigger-authoring-tasks","author backend Trigger.dev tasks","Covers writing backend Trigger.dev tasks with @trigger.dev\u002Fsdk: defining task() and schemaTask(), the run function and its ctx, retries, waits, queues and concurrency, idempotency keys, run metadata, logging, triggering other tasks (and the Result shape), scheduled\u002Fcron tasks, and the essentials of trigger.config.ts. Load this whenever you are authoring or editing code inside a \u002Ftrigger directory, defining a task, or writing backend code that triggers tasks. Realtime\u002FReact hooks and AI chat are covered by separate skills.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3467,3470,3471,3472],{"name":3468,"slug":3469,"type":16},"Backend","backend",{"name":3452,"slug":3453,"type":16},{"name":9,"slug":8,"type":16},{"name":3456,"slug":3457,"type":16},"2026-07-02T17:12:48.396964",{"slug":3475,"name":3475,"fn":3476,"description":3477,"org":3478,"tags":3479,"stars":3458,"repoUrl":3459,"updatedAt":3483},"trigger-chat-agent-advanced","manage Trigger.dev chat sessions and transports","Advanced and operational chat.agent capabilities for Trigger.dev, loaded on demand. Load this when working on the raw Sessions primitive (sessions \u002F SessionHandle), a custom chat transport or the realtime wire protocol, durable sub-agents (AgentChat, chat.stream.writer), human-in-the-loop, steering, actions, background injection (chat.defer \u002F chat.inject), fast starts (preload, Head Start via @trigger.dev\u002Fsdk\u002Fchat-server), context resilience (compaction, recovery boot, OOM, large payloads), chat.local run-scoped state, offline testing with mockChatAgent, or prerelease\u002Fversion upgrades. For the everyday chat.agent({...}) definition and the useTriggerChatTransport happy path, use the trigger-authoring-chat-agent skill instead.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3480,3481,3482],{"name":3449,"slug":3450,"type":16},{"name":9,"slug":8,"type":16},{"name":3456,"slug":3457,"type":16},"2026-07-02T17:12:51.03018",{"slug":3485,"name":3485,"fn":3486,"description":3487,"org":3488,"tags":3489,"stars":3458,"repoUrl":3459,"updatedAt":3500},"trigger-realtime-and-frontend","subscribe to Trigger.dev runs in realtime","Trigger.dev client\u002Ffrontend surface: subscribe to runs in realtime (runs.subscribeToRun and the @trigger.dev\u002Freact-hooks hook useRealtimeRun), consume metadata and AI\u002Ftext streams in React (useRealtimeStream), trigger tasks from the browser (useTaskTrigger, useRealtimeTaskTrigger), and mint scoped frontend credentials with auth.createPublicToken \u002F auth.createTriggerPublicToken. Load when wiring a frontend (React\u002FNext.js\u002FRemix) or backend-for-frontend to show live run progress, status badges, token streams, trigger buttons, or wait-token approval UIs. NOT for writing the backend task itself (streams.define \u002F metadata.set is trigger-authoring-tasks territory); this is the consumer side.\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3490,3493,3496,3499],{"name":3491,"slug":3492,"type":16},"Frontend","frontend",{"name":3494,"slug":3495,"type":16},"React","react",{"name":3497,"slug":3498,"type":16},"Real-time","real-time",{"name":9,"slug":8,"type":16},"2026-07-02T17:12:49.717706",{"slug":3502,"name":3502,"fn":3503,"description":3504,"org":3505,"tags":3506,"stars":3513,"repoUrl":3514,"updatedAt":3515},"trigger-agents","orchestrate AI agents with Trigger.dev","AI agent patterns with Trigger.dev - orchestration, parallelization, routing, evaluator-optimizer, and human-in-the-loop. Use when building LLM-powered tasks that need parallel workers, approval gates, tool calling, or multi-step agent workflows.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3507,3508,3511,3512],{"name":3449,"slug":3450,"type":16},{"name":3509,"slug":3510,"type":16},"Multi-Agent","multi-agent",{"name":9,"slug":8,"type":16},{"name":3456,"slug":3457,"type":16},30,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fskills","2026-04-06T18:54:46.023553",{"slug":3517,"name":3517,"fn":3518,"description":3519,"org":3520,"tags":3521,"stars":3513,"repoUrl":3514,"updatedAt":3529},"trigger-config","configure Trigger.dev project settings","Configure Trigger.dev projects with trigger.config.ts. Use when setting up build extensions for Prisma, Playwright, FFmpeg, Python, or customizing deployment settings.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3522,3525,3528],{"name":3523,"slug":3524,"type":16},"Configuration","configuration",{"name":3526,"slug":3527,"type":16},"Deployment","deployment",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:44.764258",{"slug":3531,"name":3531,"fn":3532,"description":3533,"org":3534,"tags":3535,"stars":3513,"repoUrl":3514,"updatedAt":3546},"trigger-cost-savings","optimize Trigger.dev task costs","Analyze Trigger.dev tasks, schedules, and runs for cost optimization opportunities. Use when asked to reduce spend, optimize costs, audit usage, right-size machines, or review task efficiency. Requires Trigger.dev MCP tools for run analysis.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3536,3539,3542,3545],{"name":3537,"slug":3538,"type":16},"Analytics","analytics",{"name":3540,"slug":3541,"type":16},"Cost Optimization","cost-optimization",{"name":3543,"slug":3544,"type":16},"Operations","operations",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:48.555552",{"slug":3548,"name":3548,"fn":3549,"description":3550,"org":3551,"tags":3552,"stars":3513,"repoUrl":3514,"updatedAt":3559},"trigger-realtime","monitor Trigger.dev tasks in real-time","Subscribe to Trigger.dev task runs in real-time from frontend and backend. Use when building progress indicators, live dashboards, streaming AI\u002FLLM responses, or React components that display task status.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3553,3554,3557,3558],{"name":3491,"slug":3492,"type":16},{"name":3555,"slug":3556,"type":16},"Observability","observability",{"name":3497,"slug":3498,"type":16},{"name":9,"slug":8,"type":16},"2026-04-06T18:54:47.293822",{"slug":3561,"name":3561,"fn":3562,"description":3563,"org":3564,"tags":3565,"stars":3513,"repoUrl":3514,"updatedAt":3571},"trigger-setup","set up Trigger.dev in projects","Set up Trigger.dev in your project. Use when adding Trigger.dev for the first time, creating trigger.config.ts, or initializing the trigger directory.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3566,3567,3570],{"name":3523,"slug":3524,"type":16},{"name":3568,"slug":3569,"type":16},"Local Development","local-development",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:42.280816",{"slug":3573,"name":3573,"fn":3574,"description":3575,"org":3576,"tags":3577,"stars":3513,"repoUrl":3514,"updatedAt":3582},"trigger-tasks","build durable background tasks with Trigger.dev","Build AI agents, workflows and durable background tasks with Trigger.dev. Use when creating tasks, triggering jobs, handling retries, scheduling cron jobs, or implementing queues and concurrency control.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3578,3579,3580,3581],{"name":3449,"slug":3450,"type":16},{"name":3468,"slug":3469,"type":16},{"name":9,"slug":8,"type":16},{"name":3456,"slug":3457,"type":16},"2026-04-06T18:54:43.514369",{"slug":3584,"name":3584,"fn":3585,"description":3586,"org":3587,"tags":3588,"stars":23,"repoUrl":24,"updatedAt":3593},"staff-engineering-skills-backpressure","implement backpressure in streaming pipelines","Prevent unbounded resource growth when producers outpace consumers. Use when writing producer-consumer code, queue processing, batch operations, fan-out patterns, streaming pipelines, or any code where work is generated faster than it can be processed. Activates on patterns like Promise.all on dynamic-sized arrays, unbounded in-memory queues, producer loops without depth checks, fire-and-forget async calls in loops, or any buffer between a producer and consumer without a size limit.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3589,3590],{"name":14,"slug":15,"type":16},{"name":3591,"slug":3592,"type":16},"Performance","performance","2026-06-17T08:40:42.723559",{"slug":3595,"name":3595,"fn":3596,"description":3597,"org":3598,"tags":3599,"stars":23,"repoUrl":24,"updatedAt":3606},"staff-engineering-skills-cache-invalidation","implement cache invalidation strategies","Prevent stale data bugs caused by missing or incomplete cache invalidation. Use when adding caching layers (Redis, in-memory Map, CDN, HTTP cache headers), optimizing read performance, or reviewing code that caches query results, API responses, or computed values. Activates on patterns like cache.set without cache.delete on write paths, unbounded Map\u002Fobject caches, TTL-only invalidation on security-sensitive data, Cache-Control headers on mutable content, or any caching where the write path doesn't invalidate the read cache.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3600,3601,3604,3605],{"name":14,"slug":15,"type":16},{"name":3602,"slug":3603,"type":16},"Caching","caching",{"name":18,"slug":19,"type":16},{"name":3591,"slug":3592,"type":16},"2026-06-17T08:40:45.194583",{"items":3608,"total":2197},[3609,3614,3621,3631,3637,3650,3662],{"slug":3584,"name":3584,"fn":3585,"description":3586,"org":3610,"tags":3611,"stars":23,"repoUrl":24,"updatedAt":3593},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3612,3613],{"name":14,"slug":15,"type":16},{"name":3591,"slug":3592,"type":16},{"slug":3595,"name":3595,"fn":3596,"description":3597,"org":3615,"tags":3616,"stars":23,"repoUrl":24,"updatedAt":3606},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3617,3618,3619,3620],{"name":14,"slug":15,"type":16},{"name":3602,"slug":3603,"type":16},{"name":18,"slug":19,"type":16},{"name":3591,"slug":3592,"type":16},{"slug":3622,"name":3622,"fn":3623,"description":3624,"org":3625,"tags":3626,"stars":23,"repoUrl":24,"updatedAt":3630},"staff-engineering-skills-cardinality","prevent cardinality traps in systems code","Detect and prevent cardinality traps in systems code. Use when writing code that iterates over collections, stores items in memory, creates per-entity resources, or fans out operations across a set of items. Activates on patterns like loops over query results, in-memory Maps\u002FSets populated from databases, or \"one X per Y\" resource allocation.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3627,3628,3629],{"name":14,"slug":15,"type":16},{"name":18,"slug":19,"type":16},{"name":3591,"slug":3592,"type":16},"2026-06-17T08:40:40.264608",{"slug":4,"name":4,"fn":5,"description":6,"org":3632,"tags":3633,"stars":23,"repoUrl":24,"updatedAt":25},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3634,3635,3636],{"name":14,"slug":15,"type":16},{"name":21,"slug":22,"type":16},{"name":18,"slug":19,"type":16},{"slug":3638,"name":3638,"fn":3639,"description":3640,"org":3641,"tags":3642,"stars":23,"repoUrl":24,"updatedAt":3649},"staff-engineering-skills-consistency-models","manage consistency models in distributed systems","Prevent stale read bugs caused by replica lag, cache staleness, and index delay. Use when writing code that reads data after writing it, uses read replicas, caches query results, reads from search indexes, or builds event-driven read models. Activates on patterns like create-then-redirect, update-then-read, cache-aside with TTL, search-after-create, or any write followed by a read that might hit a different data source.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3643,3644,3647,3648],{"name":14,"slug":15,"type":16},{"name":3645,"slug":3646,"type":16},"Database","database",{"name":18,"slug":19,"type":16},{"name":3591,"slug":3592,"type":16},"2026-06-17T08:40:46.442182",{"slug":3651,"name":3651,"fn":3652,"description":3653,"org":3654,"tags":3655,"stars":23,"repoUrl":24,"updatedAt":3661},"staff-engineering-skills-denormalization","prevent data model denormalization traps","Detect and prevent denormalization traps when designing data models. Use when writing code that copies fields between tables, embeds related data in documents, caches composed objects, or adds redundant columns to avoid joins. Activates on patterns like storing derived\u002Fcopied data, syncing fields across tables, or embedding nested objects in document stores.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3656,3657,3660],{"name":14,"slug":15,"type":16},{"name":3658,"slug":3659,"type":16},"Data Modeling","data-modeling",{"name":3645,"slug":3646,"type":16},"2026-06-17T08:40:53.835868",{"slug":3663,"name":3663,"fn":3664,"description":3665,"org":3666,"tags":3667,"stars":23,"repoUrl":24,"updatedAt":3673},"staff-engineering-skills-distributed-system-fallacies","design resilient distributed systems","Prevent failures caused by treating network calls like function calls. Use when writing code that calls external services, splits a monolith into microservices, chains multiple API calls, orchestrates distributed workflows, or handles requests that depend on other services. Activates on patterns like sequential service calls without timeouts, fetch\u002Faxios calls without error handling, multi-service writes without compensation, hardcoded service URLs, or any code that assumes the network is reliable, fast, or free.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3668,3671,3672],{"name":3669,"slug":3670,"type":16},"API Development","api-development",{"name":14,"slug":15,"type":16},{"name":18,"slug":19,"type":16},"2026-06-17T08:40:47.666795"]