[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-trigger-dev-staff-engineering-skills-hot-partitions":3,"mdc-yffbat-key":37,"related-repo-trigger-dev-staff-engineering-skills-hot-partitions":3458,"related-org-trigger-dev-staff-engineering-skills-hot-partitions":3538},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":12,"stars":26,"repoUrl":27,"updatedAt":28,"license":29,"forks":30,"topics":31,"repo":32,"sourceUrl":35,"mdContent":36},"staff-engineering-skills-hot-partitions","prevent hot partitions in distributed databases","Prevent disproportionate load on individual partitions, shards, or nodes. Use when choosing partition keys, designing sharded databases, writing to Kafka topics, using DynamoDB, partitioning tables by date, or working with any system where data is distributed across multiple nodes. Activates on patterns like partitioning by date for write-heavy data, low-cardinality partition keys (country, status), tenant-based sharding without hot-tenant handling, single global keys in DynamoDB, or any partition scheme without per-partition monitoring.",{"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,23],{"name":14,"slug":15,"type":16},"Performance","performance","tag",{"name":18,"slug":19,"type":16},"Architecture","architecture",{"name":21,"slug":22,"type":16},"Database","database",{"name":24,"slug":25,"type":16},"Engineering","engineering",3,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills","2026-06-17T08:40:43.950057",null,1,[],{"repoUrl":27,"stars":26,"forks":30,"topics":33,"description":34},[],"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-hot-partitions","---\nname: staff-engineering-skills-hot-partitions\ndescription: Prevent disproportionate load on individual partitions, shards, or nodes. Use when choosing partition keys, designing sharded databases, writing to Kafka topics, using DynamoDB, partitioning tables by date, or working with any system where data is distributed across multiple nodes. Activates on patterns like partitioning by date for write-heavy data, low-cardinality partition keys (country, status), tenant-based sharding without hot-tenant handling, single global keys in DynamoDB, or any partition scheme without per-partition monitoring.\n---\n\n# Hot Partitions Trap\n\nYou distributed the data evenly. But traffic isn't even -- one partition is on fire. Before choosing a partition key, ask: **does this key distribute access patterns, not just data?**\n\n## The Core Problem\n\nData distribution and access distribution are different things. Ten million users across 100 partitions is 100,000 users per partition. But if one user generates 50% of traffic, that user's partition handles 50% of total load. You've built a distributed system that behaves like a single node.\n\nReal traffic follows power laws. A small number of entities generate most of the activity. Your partition scheme must account for this.\n\n## Detection: When You're Creating a Hot Partition\n\n**Stop and fix if you see:**\n\n1. **Partitioning by date\u002Ftimestamp for write-heavy data** -- today's partition receives ALL writes. Yesterday's is idle. This is the most common hot partition pattern for time-series, events, and logs.\n\n2. **Partitioning by a low-cardinality key** -- country code (US gets 50%), status field (90% are \"active\"), boolean flags. Low cardinality means few partitions, and the most common value dominates.\n\n3. **A single global key in DynamoDB** -- `pk = \"global-leaderboard\"` or `pk = \"config\"`. Every request for that item hits the same partition. DynamoDB partitions can handle ~3,000 RCU \u002F ~1,000 WCU per second per partition key.\n\n4. **Kafka topic keyed by something skewed** -- `key: user.countryCode` means one Kafka partition gets half the world's messages. One consumer handles that partition and falls behind while 31 others are idle. Adding consumers doesn't help (Kafka assigns one consumer per partition).\n\n5. **Tenant-based sharding with no hot-tenant handling** -- `hash(tenantId) % numShards`. The enterprise tenant generating 40% of queries lands on one shard. That shard is permanently overloaded.\n\n6. **No per-partition monitoring** -- without metrics per partition, you won't know one is hot until it causes an outage. Per-partition metrics are not optional.\n\n## Patterns\n\n### Write sharding with random suffix\n\nSpread writes for a hot key across multiple physical partitions.\n\n```typescript\nconst WRITE_SHARDS = 10;\n\nasync function writeEvent(date: string, event: Event) {\n  const shard = Math.floor(Math.random() * WRITE_SHARDS);\n  await dynamodb.put({\n    TableName: \"events\",\n    Item: { pk: `${date}#${shard}`, sk: event.eventId, ...event },\n  });\n}\n\n\u002F\u002F Reads scatter-gather across all shards\nasync function readEvents(date: string): Promise\u003CEvent[]> {\n  const results = await Promise.all(\n    Array.from({ length: WRITE_SHARDS }, (_, i) =>\n      dynamodb.query({\n        TableName: \"events\",\n        KeyConditionExpression: \"pk = :pk\",\n        ExpressionAttributeValues: { \":pk\": `${date}#${i}` },\n      })\n    )\n  );\n  return results.flatMap((r) => r.Items as Event[]);\n}\n```\n\n**Tradeoff:** Writes are perfectly distributed. Reads require scatter-gather (query all shards and merge), increasing latency and cost. Use when the workload is write-heavy or the hot key is known in advance.\n\n### Composite partition keys\n\nAdd a second dimension to increase cardinality and spread load.\n\n```typescript\n\u002F\u002F BAD: tenant alone is low-cardinality for hot tenants\nconst pk = tenantId; \u002F\u002F \"acme-corp\" gets 40% of traffic\n\n\u002F\u002F GOOD: combine with entity type or time bucket\nconst pk = `${tenantId}#${entityType}`;\n\u002F\u002F \"acme-corp#invoices\", \"acme-corp#users\", \"acme-corp#events\"\n\n\u002F\u002F GOOD: combine with time bucket for write-heavy patterns\nconst hourBucket = new Date().toISOString().slice(0, 13); \u002F\u002F \"2024-01-15T14\"\nconst pk = `${tenantId}#${hourBucket}`;\n```\n\n**Tradeoff:** Only helps if the secondary dimension has enough cardinality. If the hot tenant does one thing, compositing doesn't spread the load.\n\n### Dedicated infrastructure for hot tenants\n\n```typescript\nconst DEDICATED_TENANTS = new Map\u003Cstring, Database>([\n  [\"acme-corp\", acmeDatabase],\n  [\"megacorp\", megacorpDatabase],\n]);\n\nfunction getDatabaseForTenant(tenantId: string): Database {\n  const dedicated = DEDICATED_TENANTS.get(tenantId);\n  if (dedicated) return dedicated; \u002F\u002F Hot tenant gets their own infrastructure\n\n  const shardIndex = hash(tenantId) % NUM_SHARED_SHARDS;\n  return sharedShards[shardIndex];\n}\n```\n\n**Tradeoff:** Operational complexity -- you manage per-tenant infrastructure. But it completely isolates hot tenant load from everyone else. This is the standard pattern for enterprise SaaS at scale.\n\n### Cache layer for hot reads\n\nWhen a key is read-hot (many reads, few writes), cache it aggressively.\n\n```typescript\nasync function getLeaderboard(): Promise\u003CLeaderboardEntry[]> {\n  const cached = await cache.get(\"global-leaderboard\");\n  if (cached) return JSON.parse(cached);\n\n  \u002F\u002F Use stampede protection (see Thundering Herd skill)\n  const data = await fetchWithCoalescing(\"global-leaderboard\", () =>\n    db.query(\"SELECT * FROM leaderboard ORDER BY score DESC LIMIT 100\")\n  );\n\n  await cache.set(\"global-leaderboard\", JSON.stringify(data), { EX: 10 });\n  return data;\n}\n```\n\n**Tradeoff:** Adds staleness (up to TTL seconds old). Doesn't help with write-hot partitions. Combine with stampede protection to avoid thundering herd when the cache expires.\n\n### Higher-cardinality Kafka partition keys\n\n```typescript\n\u002F\u002F BAD: country code has ~200 values, US dominates\nawait producer.send({\n  topic: \"user-events\",\n  messages: [{ key: user.countryCode, value: JSON.stringify(event) }],\n});\n\n\u002F\u002F GOOD: user_id has millions of values, distributes evenly\nawait producer.send({\n  topic: \"user-events\",\n  messages: [{ key: user.id, value: JSON.stringify(event) }],\n});\n\n\u002F\u002F GOOD: for a known hot key, add a random suffix\nconst key = isHotUser(user.id)\n  ? `${user.id}-${Math.floor(Math.random() * 8)}` \u002F\u002F Spread across 8 partitions\n  : user.id;\n```\n\n**Tradeoff:** Changing the partition key changes message ordering guarantees. Messages for the same user may land on different partitions with the random suffix, losing per-user ordering. Only use the suffix for keys where ordering doesn't matter.\n\n### Per-partition monitoring\n\n```typescript\nfunction recordPartitionAccess(partitionKey: string, operation: \"read\" | \"write\") {\n  metrics.increment(\"partition.operations\", { partition: partitionKey, operation });\n}\n\n\u002F\u002F Alert when:\n\u002F\u002F - One partition exceeds 3x the average operations\n\u002F\u002F - Partition utilization exceeds 80% of its throughput limit\n\u002F\u002F - Consumer lag on one Kafka partition grows while others are stable\n```\n\nThis is not optional. Without per-partition metrics, you won't know a partition is hot until users report errors or the system pages you.\n\n## The Read\u002FWrite Tradeoff\n\nEvery hot partition fix has a read\u002Fwrite tradeoff:\n\n| Technique | Writes | Reads | Best for |\n|-----------|--------|-------|----------|\n| Random suffix sharding | Distributed perfectly | Scatter-gather (slower, costlier) | Write-heavy hot keys |\n| Caching | Unchanged | Absorbed by cache | Read-heavy hot keys |\n| Dedicated infrastructure | Isolated | Isolated | Known hot tenants |\n| Composite keys | Spread across dimensions | Must know the dimension to query | Mixed workloads |\n\nThere is no technique that makes both reads and writes better. You're always trading one for the other.\n\n## Anti-Patterns\n\n```typescript\n\u002F\u002F Date partition for writes: today gets ALL writes\nconst pk = new Date().toISOString().split(\"T\")[0]; \u002F\u002F \"2024-01-15\"\n\n\u002F\u002F Low-cardinality Kafka key: US gets 50% of messages\nmessages: [{ key: user.countryCode, value: event }]\n\n\u002F\u002F Single global DynamoDB key: one partition handles all reads\nKeyConditionExpression: \"pk = :pk\", { \":pk\": \"global-config\" }\n\n\u002F\u002F Naive tenant sharding: enterprise tenant overloads one shard\nconst shard = hash(tenantId) % NUM_SHARDS;\n\n\u002F\u002F No per-partition monitoring: blind to imbalance\n\u002F\u002F You find out when users report errors, not from metrics\n```\n\n## Related Traps\n\n- **Cardinality** -- low cardinality in partition keys directly causes hot partitions. If your key has 5 distinct values, you have at most 5 partitions, and the most popular value dominates.\n- **Thundering Herd** -- a thundering herd on a partitioned system concentrates the stampede on one partition. Cache expiry for a hot key creates both problems simultaneously.\n- **Sharding** -- hot partitions are the failure mode of bad shard key selection. The Sharding skill covers shard key choice; this skill covers what happens when the choice is wrong.\n",{"data":38,"body":39},{"name":4,"description":6},{"type":40,"children":41},"root",[42,51,63,70,75,80,86,94,190,196,203,208,1078,1088,1094,1099,1364,1373,1379,1743,1752,1758,1763,2174,2183,2189,2691,2700,2706,2916,2921,2927,2932,3061,3066,3072,3412,3418,3452],{"type":43,"tag":44,"props":45,"children":47},"element","h1",{"id":46},"hot-partitions-trap",[48],{"type":49,"value":50},"text","Hot Partitions Trap",{"type":43,"tag":52,"props":53,"children":54},"p",{},[55,57],{"type":49,"value":56},"You distributed the data evenly. But traffic isn't even -- one partition is on fire. Before choosing a partition key, ask: ",{"type":43,"tag":58,"props":59,"children":60},"strong",{},[61],{"type":49,"value":62},"does this key distribute access patterns, not just data?",{"type":43,"tag":64,"props":65,"children":67},"h2",{"id":66},"the-core-problem",[68],{"type":49,"value":69},"The Core Problem",{"type":43,"tag":52,"props":71,"children":72},{},[73],{"type":49,"value":74},"Data distribution and access distribution are different things. Ten million users across 100 partitions is 100,000 users per partition. But if one user generates 50% of traffic, that user's partition handles 50% of total load. You've built a distributed system that behaves like a single node.",{"type":43,"tag":52,"props":76,"children":77},{},[78],{"type":49,"value":79},"Real traffic follows power laws. A small number of entities generate most of the activity. Your partition scheme must account for this.",{"type":43,"tag":64,"props":81,"children":83},{"id":82},"detection-when-youre-creating-a-hot-partition",[84],{"type":49,"value":85},"Detection: When You're Creating a Hot Partition",{"type":43,"tag":52,"props":87,"children":88},{},[89],{"type":43,"tag":58,"props":90,"children":91},{},[92],{"type":49,"value":93},"Stop and fix if you see:",{"type":43,"tag":95,"props":96,"children":97},"ol",{},[98,109,119,146,163,180],{"type":43,"tag":99,"props":100,"children":101},"li",{},[102,107],{"type":43,"tag":58,"props":103,"children":104},{},[105],{"type":49,"value":106},"Partitioning by date\u002Ftimestamp for write-heavy data",{"type":49,"value":108}," -- today's partition receives ALL writes. Yesterday's is idle. This is the most common hot partition pattern for time-series, events, and logs.",{"type":43,"tag":99,"props":110,"children":111},{},[112,117],{"type":43,"tag":58,"props":113,"children":114},{},[115],{"type":49,"value":116},"Partitioning by a low-cardinality key",{"type":49,"value":118}," -- country code (US gets 50%), status field (90% are \"active\"), boolean flags. Low cardinality means few partitions, and the most common value dominates.",{"type":43,"tag":99,"props":120,"children":121},{},[122,127,129,136,138,144],{"type":43,"tag":58,"props":123,"children":124},{},[125],{"type":49,"value":126},"A single global key in DynamoDB",{"type":49,"value":128}," -- ",{"type":43,"tag":130,"props":131,"children":133},"code",{"className":132},[],[134],{"type":49,"value":135},"pk = \"global-leaderboard\"",{"type":49,"value":137}," or ",{"type":43,"tag":130,"props":139,"children":141},{"className":140},[],[142],{"type":49,"value":143},"pk = \"config\"",{"type":49,"value":145},". Every request for that item hits the same partition. DynamoDB partitions can handle ~3,000 RCU \u002F ~1,000 WCU per second per partition key.",{"type":43,"tag":99,"props":147,"children":148},{},[149,154,155,161],{"type":43,"tag":58,"props":150,"children":151},{},[152],{"type":49,"value":153},"Kafka topic keyed by something skewed",{"type":49,"value":128},{"type":43,"tag":130,"props":156,"children":158},{"className":157},[],[159],{"type":49,"value":160},"key: user.countryCode",{"type":49,"value":162}," means one Kafka partition gets half the world's messages. One consumer handles that partition and falls behind while 31 others are idle. Adding consumers doesn't help (Kafka assigns one consumer per partition).",{"type":43,"tag":99,"props":164,"children":165},{},[166,171,172,178],{"type":43,"tag":58,"props":167,"children":168},{},[169],{"type":49,"value":170},"Tenant-based sharding with no hot-tenant handling",{"type":49,"value":128},{"type":43,"tag":130,"props":173,"children":175},{"className":174},[],[176],{"type":49,"value":177},"hash(tenantId) % numShards",{"type":49,"value":179},". The enterprise tenant generating 40% of queries lands on one shard. That shard is permanently overloaded.",{"type":43,"tag":99,"props":181,"children":182},{},[183,188],{"type":43,"tag":58,"props":184,"children":185},{},[186],{"type":49,"value":187},"No per-partition monitoring",{"type":49,"value":189}," -- without metrics per partition, you won't know one is hot until it causes an outage. Per-partition metrics are not optional.",{"type":43,"tag":64,"props":191,"children":193},{"id":192},"patterns",[194],{"type":49,"value":195},"Patterns",{"type":43,"tag":197,"props":198,"children":200},"h3",{"id":199},"write-sharding-with-random-suffix",[201],{"type":49,"value":202},"Write sharding with random suffix",{"type":43,"tag":52,"props":204,"children":205},{},[206],{"type":49,"value":207},"Spread writes for a hot key across multiple physical partitions.",{"type":43,"tag":209,"props":210,"children":215},"pre",{"className":211,"code":212,"language":213,"meta":214,"style":214},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","const WRITE_SHARDS = 10;\n\nasync function writeEvent(date: string, event: Event) {\n  const shard = Math.floor(Math.random() * WRITE_SHARDS);\n  await dynamodb.put({\n    TableName: \"events\",\n    Item: { pk: `${date}#${shard}`, sk: event.eventId, ...event },\n  });\n}\n\n\u002F\u002F Reads scatter-gather across all shards\nasync function readEvents(date: string): Promise\u003CEvent[]> {\n  const results = await Promise.all(\n    Array.from({ length: WRITE_SHARDS }, (_, i) =>\n      dynamodb.query({\n        TableName: \"events\",\n        KeyConditionExpression: \"pk = :pk\",\n        ExpressionAttributeValues: { \":pk\": `${date}#${i}` },\n      })\n    )\n  );\n  return results.flatMap((r) => r.Items as Event[]);\n}\n","typescript","",[216],{"type":43,"tag":130,"props":217,"children":218},{"__ignoreMap":214},[219,253,263,333,409,442,476,582,599,608,616,626,693,733,806,832,861,891,958,972,981,994,1070],{"type":43,"tag":220,"props":221,"children":223},"span",{"class":222,"line":30},"line",[224,230,236,242,248],{"type":43,"tag":220,"props":225,"children":227},{"style":226},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[228],{"type":49,"value":229},"const",{"type":43,"tag":220,"props":231,"children":233},{"style":232},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[234],{"type":49,"value":235}," WRITE_SHARDS ",{"type":43,"tag":220,"props":237,"children":239},{"style":238},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[240],{"type":49,"value":241},"=",{"type":43,"tag":220,"props":243,"children":245},{"style":244},"--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C",[246],{"type":49,"value":247}," 10",{"type":43,"tag":220,"props":249,"children":250},{"style":238},[251],{"type":49,"value":252},";\n",{"type":43,"tag":220,"props":254,"children":256},{"class":222,"line":255},2,[257],{"type":43,"tag":220,"props":258,"children":260},{"emptyLinePlaceholder":259},true,[261],{"type":49,"value":262},"\n",{"type":43,"tag":220,"props":264,"children":265},{"class":222,"line":26},[266,271,276,282,287,293,298,304,309,314,318,323,328],{"type":43,"tag":220,"props":267,"children":268},{"style":226},[269],{"type":49,"value":270},"async",{"type":43,"tag":220,"props":272,"children":273},{"style":226},[274],{"type":49,"value":275}," function",{"type":43,"tag":220,"props":277,"children":279},{"style":278},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[280],{"type":49,"value":281}," writeEvent",{"type":43,"tag":220,"props":283,"children":284},{"style":238},[285],{"type":49,"value":286},"(",{"type":43,"tag":220,"props":288,"children":290},{"style":289},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic",[291],{"type":49,"value":292},"date",{"type":43,"tag":220,"props":294,"children":295},{"style":238},[296],{"type":49,"value":297},":",{"type":43,"tag":220,"props":299,"children":301},{"style":300},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[302],{"type":49,"value":303}," string",{"type":43,"tag":220,"props":305,"children":306},{"style":238},[307],{"type":49,"value":308},",",{"type":43,"tag":220,"props":310,"children":311},{"style":289},[312],{"type":49,"value":313}," event",{"type":43,"tag":220,"props":315,"children":316},{"style":238},[317],{"type":49,"value":297},{"type":43,"tag":220,"props":319,"children":320},{"style":300},[321],{"type":49,"value":322}," Event",{"type":43,"tag":220,"props":324,"children":325},{"style":238},[326],{"type":49,"value":327},")",{"type":43,"tag":220,"props":329,"children":330},{"style":238},[331],{"type":49,"value":332}," {\n",{"type":43,"tag":220,"props":334,"children":336},{"class":222,"line":335},4,[337,342,347,352,357,362,367,372,377,381,386,391,396,401,405],{"type":43,"tag":220,"props":338,"children":339},{"style":226},[340],{"type":49,"value":341},"  const",{"type":43,"tag":220,"props":343,"children":344},{"style":232},[345],{"type":49,"value":346}," shard",{"type":43,"tag":220,"props":348,"children":349},{"style":238},[350],{"type":49,"value":351}," =",{"type":43,"tag":220,"props":353,"children":354},{"style":232},[355],{"type":49,"value":356}," Math",{"type":43,"tag":220,"props":358,"children":359},{"style":238},[360],{"type":49,"value":361},".",{"type":43,"tag":220,"props":363,"children":364},{"style":278},[365],{"type":49,"value":366},"floor",{"type":43,"tag":220,"props":368,"children":370},{"style":369},"--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178",[371],{"type":49,"value":286},{"type":43,"tag":220,"props":373,"children":374},{"style":232},[375],{"type":49,"value":376},"Math",{"type":43,"tag":220,"props":378,"children":379},{"style":238},[380],{"type":49,"value":361},{"type":43,"tag":220,"props":382,"children":383},{"style":278},[384],{"type":49,"value":385},"random",{"type":43,"tag":220,"props":387,"children":388},{"style":369},[389],{"type":49,"value":390},"() ",{"type":43,"tag":220,"props":392,"children":393},{"style":238},[394],{"type":49,"value":395},"*",{"type":43,"tag":220,"props":397,"children":398},{"style":232},[399],{"type":49,"value":400}," WRITE_SHARDS",{"type":43,"tag":220,"props":402,"children":403},{"style":369},[404],{"type":49,"value":327},{"type":43,"tag":220,"props":406,"children":407},{"style":238},[408],{"type":49,"value":252},{"type":43,"tag":220,"props":410,"children":412},{"class":222,"line":411},5,[413,419,424,428,433,437],{"type":43,"tag":220,"props":414,"children":416},{"style":415},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[417],{"type":49,"value":418},"  await",{"type":43,"tag":220,"props":420,"children":421},{"style":232},[422],{"type":49,"value":423}," dynamodb",{"type":43,"tag":220,"props":425,"children":426},{"style":238},[427],{"type":49,"value":361},{"type":43,"tag":220,"props":429,"children":430},{"style":278},[431],{"type":49,"value":432},"put",{"type":43,"tag":220,"props":434,"children":435},{"style":369},[436],{"type":49,"value":286},{"type":43,"tag":220,"props":438,"children":439},{"style":238},[440],{"type":49,"value":441},"{\n",{"type":43,"tag":220,"props":443,"children":445},{"class":222,"line":444},6,[446,451,455,460,466,471],{"type":43,"tag":220,"props":447,"children":448},{"style":369},[449],{"type":49,"value":450},"    TableName",{"type":43,"tag":220,"props":452,"children":453},{"style":238},[454],{"type":49,"value":297},{"type":43,"tag":220,"props":456,"children":457},{"style":238},[458],{"type":49,"value":459}," \"",{"type":43,"tag":220,"props":461,"children":463},{"style":462},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[464],{"type":49,"value":465},"events",{"type":43,"tag":220,"props":467,"children":468},{"style":238},[469],{"type":49,"value":470},"\"",{"type":43,"tag":220,"props":472,"children":473},{"style":238},[474],{"type":49,"value":475},",\n",{"type":43,"tag":220,"props":477,"children":479},{"class":222,"line":478},7,[480,485,489,494,499,503,508,512,517,522,527,532,537,541,546,550,554,558,563,567,572,577],{"type":43,"tag":220,"props":481,"children":482},{"style":369},[483],{"type":49,"value":484},"    Item",{"type":43,"tag":220,"props":486,"children":487},{"style":238},[488],{"type":49,"value":297},{"type":43,"tag":220,"props":490,"children":491},{"style":238},[492],{"type":49,"value":493}," {",{"type":43,"tag":220,"props":495,"children":496},{"style":369},[497],{"type":49,"value":498}," pk",{"type":43,"tag":220,"props":500,"children":501},{"style":238},[502],{"type":49,"value":297},{"type":43,"tag":220,"props":504,"children":505},{"style":238},[506],{"type":49,"value":507}," `${",{"type":43,"tag":220,"props":509,"children":510},{"style":232},[511],{"type":49,"value":292},{"type":43,"tag":220,"props":513,"children":514},{"style":238},[515],{"type":49,"value":516},"}",{"type":43,"tag":220,"props":518,"children":519},{"style":462},[520],{"type":49,"value":521},"#",{"type":43,"tag":220,"props":523,"children":524},{"style":238},[525],{"type":49,"value":526},"${",{"type":43,"tag":220,"props":528,"children":529},{"style":232},[530],{"type":49,"value":531},"shard",{"type":43,"tag":220,"props":533,"children":534},{"style":238},[535],{"type":49,"value":536},"}`",{"type":43,"tag":220,"props":538,"children":539},{"style":238},[540],{"type":49,"value":308},{"type":43,"tag":220,"props":542,"children":543},{"style":369},[544],{"type":49,"value":545}," sk",{"type":43,"tag":220,"props":547,"children":548},{"style":238},[549],{"type":49,"value":297},{"type":43,"tag":220,"props":551,"children":552},{"style":232},[553],{"type":49,"value":313},{"type":43,"tag":220,"props":555,"children":556},{"style":238},[557],{"type":49,"value":361},{"type":43,"tag":220,"props":559,"children":560},{"style":232},[561],{"type":49,"value":562},"eventId",{"type":43,"tag":220,"props":564,"children":565},{"style":238},[566],{"type":49,"value":308},{"type":43,"tag":220,"props":568,"children":569},{"style":238},[570],{"type":49,"value":571}," ...",{"type":43,"tag":220,"props":573,"children":574},{"style":232},[575],{"type":49,"value":576},"event",{"type":43,"tag":220,"props":578,"children":579},{"style":238},[580],{"type":49,"value":581}," },\n",{"type":43,"tag":220,"props":583,"children":585},{"class":222,"line":584},8,[586,591,595],{"type":43,"tag":220,"props":587,"children":588},{"style":238},[589],{"type":49,"value":590},"  }",{"type":43,"tag":220,"props":592,"children":593},{"style":369},[594],{"type":49,"value":327},{"type":43,"tag":220,"props":596,"children":597},{"style":238},[598],{"type":49,"value":252},{"type":43,"tag":220,"props":600,"children":602},{"class":222,"line":601},9,[603],{"type":43,"tag":220,"props":604,"children":605},{"style":238},[606],{"type":49,"value":607},"}\n",{"type":43,"tag":220,"props":609,"children":611},{"class":222,"line":610},10,[612],{"type":43,"tag":220,"props":613,"children":614},{"emptyLinePlaceholder":259},[615],{"type":49,"value":262},{"type":43,"tag":220,"props":617,"children":619},{"class":222,"line":618},11,[620],{"type":43,"tag":220,"props":621,"children":623},{"style":622},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[624],{"type":49,"value":625},"\u002F\u002F Reads scatter-gather across all shards\n",{"type":43,"tag":220,"props":627,"children":629},{"class":222,"line":628},12,[630,634,638,643,647,651,655,659,664,669,674,679,684,689],{"type":43,"tag":220,"props":631,"children":632},{"style":226},[633],{"type":49,"value":270},{"type":43,"tag":220,"props":635,"children":636},{"style":226},[637],{"type":49,"value":275},{"type":43,"tag":220,"props":639,"children":640},{"style":278},[641],{"type":49,"value":642}," readEvents",{"type":43,"tag":220,"props":644,"children":645},{"style":238},[646],{"type":49,"value":286},{"type":43,"tag":220,"props":648,"children":649},{"style":289},[650],{"type":49,"value":292},{"type":43,"tag":220,"props":652,"children":653},{"style":238},[654],{"type":49,"value":297},{"type":43,"tag":220,"props":656,"children":657},{"style":300},[658],{"type":49,"value":303},{"type":43,"tag":220,"props":660,"children":661},{"style":238},[662],{"type":49,"value":663},"):",{"type":43,"tag":220,"props":665,"children":666},{"style":300},[667],{"type":49,"value":668}," Promise",{"type":43,"tag":220,"props":670,"children":671},{"style":238},[672],{"type":49,"value":673},"\u003C",{"type":43,"tag":220,"props":675,"children":676},{"style":300},[677],{"type":49,"value":678},"Event",{"type":43,"tag":220,"props":680,"children":681},{"style":232},[682],{"type":49,"value":683},"[]",{"type":43,"tag":220,"props":685,"children":686},{"style":238},[687],{"type":49,"value":688},">",{"type":43,"tag":220,"props":690,"children":691},{"style":238},[692],{"type":49,"value":332},{"type":43,"tag":220,"props":694,"children":696},{"class":222,"line":695},13,[697,701,706,710,715,719,723,728],{"type":43,"tag":220,"props":698,"children":699},{"style":226},[700],{"type":49,"value":341},{"type":43,"tag":220,"props":702,"children":703},{"style":232},[704],{"type":49,"value":705}," results",{"type":43,"tag":220,"props":707,"children":708},{"style":238},[709],{"type":49,"value":351},{"type":43,"tag":220,"props":711,"children":712},{"style":415},[713],{"type":49,"value":714}," await",{"type":43,"tag":220,"props":716,"children":717},{"style":300},[718],{"type":49,"value":668},{"type":43,"tag":220,"props":720,"children":721},{"style":238},[722],{"type":49,"value":361},{"type":43,"tag":220,"props":724,"children":725},{"style":278},[726],{"type":49,"value":727},"all",{"type":43,"tag":220,"props":729,"children":730},{"style":369},[731],{"type":49,"value":732},"(\n",{"type":43,"tag":220,"props":734,"children":736},{"class":222,"line":735},14,[737,742,746,751,755,760,765,769,773,778,783,788,792,797,801],{"type":43,"tag":220,"props":738,"children":739},{"style":232},[740],{"type":49,"value":741},"    Array",{"type":43,"tag":220,"props":743,"children":744},{"style":238},[745],{"type":49,"value":361},{"type":43,"tag":220,"props":747,"children":748},{"style":278},[749],{"type":49,"value":750},"from",{"type":43,"tag":220,"props":752,"children":753},{"style":369},[754],{"type":49,"value":286},{"type":43,"tag":220,"props":756,"children":757},{"style":238},[758],{"type":49,"value":759},"{",{"type":43,"tag":220,"props":761,"children":762},{"style":369},[763],{"type":49,"value":764}," length",{"type":43,"tag":220,"props":766,"children":767},{"style":238},[768],{"type":49,"value":297},{"type":43,"tag":220,"props":770,"children":771},{"style":232},[772],{"type":49,"value":400},{"type":43,"tag":220,"props":774,"children":775},{"style":238},[776],{"type":49,"value":777}," },",{"type":43,"tag":220,"props":779,"children":780},{"style":238},[781],{"type":49,"value":782}," (",{"type":43,"tag":220,"props":784,"children":785},{"style":289},[786],{"type":49,"value":787},"_",{"type":43,"tag":220,"props":789,"children":790},{"style":238},[791],{"type":49,"value":308},{"type":43,"tag":220,"props":793,"children":794},{"style":289},[795],{"type":49,"value":796}," i",{"type":43,"tag":220,"props":798,"children":799},{"style":238},[800],{"type":49,"value":327},{"type":43,"tag":220,"props":802,"children":803},{"style":226},[804],{"type":49,"value":805}," =>\n",{"type":43,"tag":220,"props":807,"children":809},{"class":222,"line":808},15,[810,815,819,824,828],{"type":43,"tag":220,"props":811,"children":812},{"style":232},[813],{"type":49,"value":814},"      dynamodb",{"type":43,"tag":220,"props":816,"children":817},{"style":238},[818],{"type":49,"value":361},{"type":43,"tag":220,"props":820,"children":821},{"style":278},[822],{"type":49,"value":823},"query",{"type":43,"tag":220,"props":825,"children":826},{"style":369},[827],{"type":49,"value":286},{"type":43,"tag":220,"props":829,"children":830},{"style":238},[831],{"type":49,"value":441},{"type":43,"tag":220,"props":833,"children":835},{"class":222,"line":834},16,[836,841,845,849,853,857],{"type":43,"tag":220,"props":837,"children":838},{"style":369},[839],{"type":49,"value":840},"        TableName",{"type":43,"tag":220,"props":842,"children":843},{"style":238},[844],{"type":49,"value":297},{"type":43,"tag":220,"props":846,"children":847},{"style":238},[848],{"type":49,"value":459},{"type":43,"tag":220,"props":850,"children":851},{"style":462},[852],{"type":49,"value":465},{"type":43,"tag":220,"props":854,"children":855},{"style":238},[856],{"type":49,"value":470},{"type":43,"tag":220,"props":858,"children":859},{"style":238},[860],{"type":49,"value":475},{"type":43,"tag":220,"props":862,"children":864},{"class":222,"line":863},17,[865,870,874,878,883,887],{"type":43,"tag":220,"props":866,"children":867},{"style":369},[868],{"type":49,"value":869},"        KeyConditionExpression",{"type":43,"tag":220,"props":871,"children":872},{"style":238},[873],{"type":49,"value":297},{"type":43,"tag":220,"props":875,"children":876},{"style":238},[877],{"type":49,"value":459},{"type":43,"tag":220,"props":879,"children":880},{"style":462},[881],{"type":49,"value":882},"pk = :pk",{"type":43,"tag":220,"props":884,"children":885},{"style":238},[886],{"type":49,"value":470},{"type":43,"tag":220,"props":888,"children":889},{"style":238},[890],{"type":49,"value":475},{"type":43,"tag":220,"props":892,"children":894},{"class":222,"line":893},18,[895,900,904,908,912,917,921,925,929,933,937,941,945,950,954],{"type":43,"tag":220,"props":896,"children":897},{"style":369},[898],{"type":49,"value":899},"        ExpressionAttributeValues",{"type":43,"tag":220,"props":901,"children":902},{"style":238},[903],{"type":49,"value":297},{"type":43,"tag":220,"props":905,"children":906},{"style":238},[907],{"type":49,"value":493},{"type":43,"tag":220,"props":909,"children":910},{"style":238},[911],{"type":49,"value":459},{"type":43,"tag":220,"props":913,"children":914},{"style":369},[915],{"type":49,"value":916},":pk",{"type":43,"tag":220,"props":918,"children":919},{"style":238},[920],{"type":49,"value":470},{"type":43,"tag":220,"props":922,"children":923},{"style":238},[924],{"type":49,"value":297},{"type":43,"tag":220,"props":926,"children":927},{"style":238},[928],{"type":49,"value":507},{"type":43,"tag":220,"props":930,"children":931},{"style":232},[932],{"type":49,"value":292},{"type":43,"tag":220,"props":934,"children":935},{"style":238},[936],{"type":49,"value":516},{"type":43,"tag":220,"props":938,"children":939},{"style":462},[940],{"type":49,"value":521},{"type":43,"tag":220,"props":942,"children":943},{"style":238},[944],{"type":49,"value":526},{"type":43,"tag":220,"props":946,"children":947},{"style":232},[948],{"type":49,"value":949},"i",{"type":43,"tag":220,"props":951,"children":952},{"style":238},[953],{"type":49,"value":536},{"type":43,"tag":220,"props":955,"children":956},{"style":238},[957],{"type":49,"value":581},{"type":43,"tag":220,"props":959,"children":961},{"class":222,"line":960},19,[962,967],{"type":43,"tag":220,"props":963,"children":964},{"style":238},[965],{"type":49,"value":966},"      }",{"type":43,"tag":220,"props":968,"children":969},{"style":369},[970],{"type":49,"value":971},")\n",{"type":43,"tag":220,"props":973,"children":975},{"class":222,"line":974},20,[976],{"type":43,"tag":220,"props":977,"children":978},{"style":369},[979],{"type":49,"value":980},"    )\n",{"type":43,"tag":220,"props":982,"children":984},{"class":222,"line":983},21,[985,990],{"type":43,"tag":220,"props":986,"children":987},{"style":369},[988],{"type":49,"value":989},"  )",{"type":43,"tag":220,"props":991,"children":992},{"style":238},[993],{"type":49,"value":252},{"type":43,"tag":220,"props":995,"children":997},{"class":222,"line":996},22,[998,1003,1007,1011,1016,1020,1024,1029,1033,1038,1043,1047,1052,1057,1061,1066],{"type":43,"tag":220,"props":999,"children":1000},{"style":415},[1001],{"type":49,"value":1002},"  return",{"type":43,"tag":220,"props":1004,"children":1005},{"style":232},[1006],{"type":49,"value":705},{"type":43,"tag":220,"props":1008,"children":1009},{"style":238},[1010],{"type":49,"value":361},{"type":43,"tag":220,"props":1012,"children":1013},{"style":278},[1014],{"type":49,"value":1015},"flatMap",{"type":43,"tag":220,"props":1017,"children":1018},{"style":369},[1019],{"type":49,"value":286},{"type":43,"tag":220,"props":1021,"children":1022},{"style":238},[1023],{"type":49,"value":286},{"type":43,"tag":220,"props":1025,"children":1026},{"style":289},[1027],{"type":49,"value":1028},"r",{"type":43,"tag":220,"props":1030,"children":1031},{"style":238},[1032],{"type":49,"value":327},{"type":43,"tag":220,"props":1034,"children":1035},{"style":226},[1036],{"type":49,"value":1037}," =>",{"type":43,"tag":220,"props":1039,"children":1040},{"style":232},[1041],{"type":49,"value":1042}," r",{"type":43,"tag":220,"props":1044,"children":1045},{"style":238},[1046],{"type":49,"value":361},{"type":43,"tag":220,"props":1048,"children":1049},{"style":232},[1050],{"type":49,"value":1051},"Items",{"type":43,"tag":220,"props":1053,"children":1054},{"style":415},[1055],{"type":49,"value":1056}," as",{"type":43,"tag":220,"props":1058,"children":1059},{"style":300},[1060],{"type":49,"value":322},{"type":43,"tag":220,"props":1062,"children":1063},{"style":369},[1064],{"type":49,"value":1065},"[])",{"type":43,"tag":220,"props":1067,"children":1068},{"style":238},[1069],{"type":49,"value":252},{"type":43,"tag":220,"props":1071,"children":1073},{"class":222,"line":1072},23,[1074],{"type":43,"tag":220,"props":1075,"children":1076},{"style":238},[1077],{"type":49,"value":607},{"type":43,"tag":52,"props":1079,"children":1080},{},[1081,1086],{"type":43,"tag":58,"props":1082,"children":1083},{},[1084],{"type":49,"value":1085},"Tradeoff:",{"type":49,"value":1087}," Writes are perfectly distributed. Reads require scatter-gather (query all shards and merge), increasing latency and cost. Use when the workload is write-heavy or the hot key is known in advance.",{"type":43,"tag":197,"props":1089,"children":1091},{"id":1090},"composite-partition-keys",[1092],{"type":49,"value":1093},"Composite partition keys",{"type":43,"tag":52,"props":1095,"children":1096},{},[1097],{"type":49,"value":1098},"Add a second dimension to increase cardinality and spread load.",{"type":43,"tag":209,"props":1100,"children":1102},{"className":211,"code":1101,"language":213,"meta":214,"style":214},"\u002F\u002F BAD: tenant alone is low-cardinality for hot tenants\nconst pk = tenantId; \u002F\u002F \"acme-corp\" gets 40% of traffic\n\n\u002F\u002F GOOD: combine with entity type or time bucket\nconst pk = `${tenantId}#${entityType}`;\n\u002F\u002F \"acme-corp#invoices\", \"acme-corp#users\", \"acme-corp#events\"\n\n\u002F\u002F GOOD: combine with time bucket for write-heavy patterns\nconst hourBucket = new Date().toISOString().slice(0, 13); \u002F\u002F \"2024-01-15T14\"\nconst pk = `${tenantId}#${hourBucket}`;\n",[1103],{"type":43,"tag":130,"props":1104,"children":1105},{"__ignoreMap":214},[1106,1114,1145,1152,1160,1209,1217,1224,1232,1316],{"type":43,"tag":220,"props":1107,"children":1108},{"class":222,"line":30},[1109],{"type":43,"tag":220,"props":1110,"children":1111},{"style":622},[1112],{"type":49,"value":1113},"\u002F\u002F BAD: tenant alone is low-cardinality for hot tenants\n",{"type":43,"tag":220,"props":1115,"children":1116},{"class":222,"line":255},[1117,1121,1126,1130,1135,1140],{"type":43,"tag":220,"props":1118,"children":1119},{"style":226},[1120],{"type":49,"value":229},{"type":43,"tag":220,"props":1122,"children":1123},{"style":232},[1124],{"type":49,"value":1125}," pk ",{"type":43,"tag":220,"props":1127,"children":1128},{"style":238},[1129],{"type":49,"value":241},{"type":43,"tag":220,"props":1131,"children":1132},{"style":232},[1133],{"type":49,"value":1134}," tenantId",{"type":43,"tag":220,"props":1136,"children":1137},{"style":238},[1138],{"type":49,"value":1139},";",{"type":43,"tag":220,"props":1141,"children":1142},{"style":622},[1143],{"type":49,"value":1144}," \u002F\u002F \"acme-corp\" gets 40% of traffic\n",{"type":43,"tag":220,"props":1146,"children":1147},{"class":222,"line":26},[1148],{"type":43,"tag":220,"props":1149,"children":1150},{"emptyLinePlaceholder":259},[1151],{"type":49,"value":262},{"type":43,"tag":220,"props":1153,"children":1154},{"class":222,"line":335},[1155],{"type":43,"tag":220,"props":1156,"children":1157},{"style":622},[1158],{"type":49,"value":1159},"\u002F\u002F GOOD: combine with entity type or time bucket\n",{"type":43,"tag":220,"props":1161,"children":1162},{"class":222,"line":411},[1163,1167,1171,1175,1179,1184,1188,1192,1196,1201,1205],{"type":43,"tag":220,"props":1164,"children":1165},{"style":226},[1166],{"type":49,"value":229},{"type":43,"tag":220,"props":1168,"children":1169},{"style":232},[1170],{"type":49,"value":1125},{"type":43,"tag":220,"props":1172,"children":1173},{"style":238},[1174],{"type":49,"value":241},{"type":43,"tag":220,"props":1176,"children":1177},{"style":238},[1178],{"type":49,"value":507},{"type":43,"tag":220,"props":1180,"children":1181},{"style":232},[1182],{"type":49,"value":1183},"tenantId",{"type":43,"tag":220,"props":1185,"children":1186},{"style":238},[1187],{"type":49,"value":516},{"type":43,"tag":220,"props":1189,"children":1190},{"style":462},[1191],{"type":49,"value":521},{"type":43,"tag":220,"props":1193,"children":1194},{"style":238},[1195],{"type":49,"value":526},{"type":43,"tag":220,"props":1197,"children":1198},{"style":232},[1199],{"type":49,"value":1200},"entityType",{"type":43,"tag":220,"props":1202,"children":1203},{"style":238},[1204],{"type":49,"value":536},{"type":43,"tag":220,"props":1206,"children":1207},{"style":238},[1208],{"type":49,"value":252},{"type":43,"tag":220,"props":1210,"children":1211},{"class":222,"line":444},[1212],{"type":43,"tag":220,"props":1213,"children":1214},{"style":622},[1215],{"type":49,"value":1216},"\u002F\u002F \"acme-corp#invoices\", \"acme-corp#users\", \"acme-corp#events\"\n",{"type":43,"tag":220,"props":1218,"children":1219},{"class":222,"line":478},[1220],{"type":43,"tag":220,"props":1221,"children":1222},{"emptyLinePlaceholder":259},[1223],{"type":49,"value":262},{"type":43,"tag":220,"props":1225,"children":1226},{"class":222,"line":584},[1227],{"type":43,"tag":220,"props":1228,"children":1229},{"style":622},[1230],{"type":49,"value":1231},"\u002F\u002F GOOD: combine with time bucket for write-heavy patterns\n",{"type":43,"tag":220,"props":1233,"children":1234},{"class":222,"line":601},[1235,1239,1244,1248,1253,1258,1263,1267,1272,1276,1280,1285,1289,1294,1298,1303,1307,1311],{"type":43,"tag":220,"props":1236,"children":1237},{"style":226},[1238],{"type":49,"value":229},{"type":43,"tag":220,"props":1240,"children":1241},{"style":232},[1242],{"type":49,"value":1243}," hourBucket ",{"type":43,"tag":220,"props":1245,"children":1246},{"style":238},[1247],{"type":49,"value":241},{"type":43,"tag":220,"props":1249,"children":1250},{"style":238},[1251],{"type":49,"value":1252}," new",{"type":43,"tag":220,"props":1254,"children":1255},{"style":278},[1256],{"type":49,"value":1257}," Date",{"type":43,"tag":220,"props":1259,"children":1260},{"style":232},[1261],{"type":49,"value":1262},"()",{"type":43,"tag":220,"props":1264,"children":1265},{"style":238},[1266],{"type":49,"value":361},{"type":43,"tag":220,"props":1268,"children":1269},{"style":278},[1270],{"type":49,"value":1271},"toISOString",{"type":43,"tag":220,"props":1273,"children":1274},{"style":232},[1275],{"type":49,"value":1262},{"type":43,"tag":220,"props":1277,"children":1278},{"style":238},[1279],{"type":49,"value":361},{"type":43,"tag":220,"props":1281,"children":1282},{"style":278},[1283],{"type":49,"value":1284},"slice",{"type":43,"tag":220,"props":1286,"children":1287},{"style":232},[1288],{"type":49,"value":286},{"type":43,"tag":220,"props":1290,"children":1291},{"style":244},[1292],{"type":49,"value":1293},"0",{"type":43,"tag":220,"props":1295,"children":1296},{"style":238},[1297],{"type":49,"value":308},{"type":43,"tag":220,"props":1299,"children":1300},{"style":244},[1301],{"type":49,"value":1302}," 13",{"type":43,"tag":220,"props":1304,"children":1305},{"style":232},[1306],{"type":49,"value":327},{"type":43,"tag":220,"props":1308,"children":1309},{"style":238},[1310],{"type":49,"value":1139},{"type":43,"tag":220,"props":1312,"children":1313},{"style":622},[1314],{"type":49,"value":1315}," \u002F\u002F \"2024-01-15T14\"\n",{"type":43,"tag":220,"props":1317,"children":1318},{"class":222,"line":610},[1319,1323,1327,1331,1335,1339,1343,1347,1351,1356,1360],{"type":43,"tag":220,"props":1320,"children":1321},{"style":226},[1322],{"type":49,"value":229},{"type":43,"tag":220,"props":1324,"children":1325},{"style":232},[1326],{"type":49,"value":1125},{"type":43,"tag":220,"props":1328,"children":1329},{"style":238},[1330],{"type":49,"value":241},{"type":43,"tag":220,"props":1332,"children":1333},{"style":238},[1334],{"type":49,"value":507},{"type":43,"tag":220,"props":1336,"children":1337},{"style":232},[1338],{"type":49,"value":1183},{"type":43,"tag":220,"props":1340,"children":1341},{"style":238},[1342],{"type":49,"value":516},{"type":43,"tag":220,"props":1344,"children":1345},{"style":462},[1346],{"type":49,"value":521},{"type":43,"tag":220,"props":1348,"children":1349},{"style":238},[1350],{"type":49,"value":526},{"type":43,"tag":220,"props":1352,"children":1353},{"style":232},[1354],{"type":49,"value":1355},"hourBucket",{"type":43,"tag":220,"props":1357,"children":1358},{"style":238},[1359],{"type":49,"value":536},{"type":43,"tag":220,"props":1361,"children":1362},{"style":238},[1363],{"type":49,"value":252},{"type":43,"tag":52,"props":1365,"children":1366},{},[1367,1371],{"type":43,"tag":58,"props":1368,"children":1369},{},[1370],{"type":49,"value":1085},{"type":49,"value":1372}," Only helps if the secondary dimension has enough cardinality. If the hot tenant does one thing, compositing doesn't spread the load.",{"type":43,"tag":197,"props":1374,"children":1376},{"id":1375},"dedicated-infrastructure-for-hot-tenants",[1377],{"type":49,"value":1378},"Dedicated infrastructure for hot tenants",{"type":43,"tag":209,"props":1380,"children":1382},{"className":211,"code":1381,"language":213,"meta":214,"style":214},"const DEDICATED_TENANTS = new Map\u003Cstring, Database>([\n  [\"acme-corp\", acmeDatabase],\n  [\"megacorp\", megacorpDatabase],\n]);\n\nfunction getDatabaseForTenant(tenantId: string): Database {\n  const dedicated = DEDICATED_TENANTS.get(tenantId);\n  if (dedicated) return dedicated; \u002F\u002F Hot tenant gets their own infrastructure\n\n  const shardIndex = hash(tenantId) % NUM_SHARED_SHARDS;\n  return sharedShards[shardIndex];\n}\n",[1383],{"type":43,"tag":130,"props":1384,"children":1385},{"__ignoreMap":214},[1386,1438,1472,1505,1517,1524,1565,1611,1651,1658,1705,1736],{"type":43,"tag":220,"props":1387,"children":1388},{"class":222,"line":30},[1389,1393,1398,1402,1406,1411,1415,1420,1424,1429,1433],{"type":43,"tag":220,"props":1390,"children":1391},{"style":226},[1392],{"type":49,"value":229},{"type":43,"tag":220,"props":1394,"children":1395},{"style":232},[1396],{"type":49,"value":1397}," DEDICATED_TENANTS ",{"type":43,"tag":220,"props":1399,"children":1400},{"style":238},[1401],{"type":49,"value":241},{"type":43,"tag":220,"props":1403,"children":1404},{"style":238},[1405],{"type":49,"value":1252},{"type":43,"tag":220,"props":1407,"children":1408},{"style":278},[1409],{"type":49,"value":1410}," Map",{"type":43,"tag":220,"props":1412,"children":1413},{"style":238},[1414],{"type":49,"value":673},{"type":43,"tag":220,"props":1416,"children":1417},{"style":300},[1418],{"type":49,"value":1419},"string",{"type":43,"tag":220,"props":1421,"children":1422},{"style":238},[1423],{"type":49,"value":308},{"type":43,"tag":220,"props":1425,"children":1426},{"style":300},[1427],{"type":49,"value":1428}," Database",{"type":43,"tag":220,"props":1430,"children":1431},{"style":238},[1432],{"type":49,"value":688},{"type":43,"tag":220,"props":1434,"children":1435},{"style":232},[1436],{"type":49,"value":1437},"([\n",{"type":43,"tag":220,"props":1439,"children":1440},{"class":222,"line":255},[1441,1446,1450,1455,1459,1463,1468],{"type":43,"tag":220,"props":1442,"children":1443},{"style":232},[1444],{"type":49,"value":1445},"  [",{"type":43,"tag":220,"props":1447,"children":1448},{"style":238},[1449],{"type":49,"value":470},{"type":43,"tag":220,"props":1451,"children":1452},{"style":462},[1453],{"type":49,"value":1454},"acme-corp",{"type":43,"tag":220,"props":1456,"children":1457},{"style":238},[1458],{"type":49,"value":470},{"type":43,"tag":220,"props":1460,"children":1461},{"style":238},[1462],{"type":49,"value":308},{"type":43,"tag":220,"props":1464,"children":1465},{"style":232},[1466],{"type":49,"value":1467}," acmeDatabase]",{"type":43,"tag":220,"props":1469,"children":1470},{"style":238},[1471],{"type":49,"value":475},{"type":43,"tag":220,"props":1473,"children":1474},{"class":222,"line":26},[1475,1479,1483,1488,1492,1496,1501],{"type":43,"tag":220,"props":1476,"children":1477},{"style":232},[1478],{"type":49,"value":1445},{"type":43,"tag":220,"props":1480,"children":1481},{"style":238},[1482],{"type":49,"value":470},{"type":43,"tag":220,"props":1484,"children":1485},{"style":462},[1486],{"type":49,"value":1487},"megacorp",{"type":43,"tag":220,"props":1489,"children":1490},{"style":238},[1491],{"type":49,"value":470},{"type":43,"tag":220,"props":1493,"children":1494},{"style":238},[1495],{"type":49,"value":308},{"type":43,"tag":220,"props":1497,"children":1498},{"style":232},[1499],{"type":49,"value":1500}," megacorpDatabase]",{"type":43,"tag":220,"props":1502,"children":1503},{"style":238},[1504],{"type":49,"value":475},{"type":43,"tag":220,"props":1506,"children":1507},{"class":222,"line":335},[1508,1513],{"type":43,"tag":220,"props":1509,"children":1510},{"style":232},[1511],{"type":49,"value":1512},"])",{"type":43,"tag":220,"props":1514,"children":1515},{"style":238},[1516],{"type":49,"value":252},{"type":43,"tag":220,"props":1518,"children":1519},{"class":222,"line":411},[1520],{"type":43,"tag":220,"props":1521,"children":1522},{"emptyLinePlaceholder":259},[1523],{"type":49,"value":262},{"type":43,"tag":220,"props":1525,"children":1526},{"class":222,"line":444},[1527,1532,1537,1541,1545,1549,1553,1557,1561],{"type":43,"tag":220,"props":1528,"children":1529},{"style":226},[1530],{"type":49,"value":1531},"function",{"type":43,"tag":220,"props":1533,"children":1534},{"style":278},[1535],{"type":49,"value":1536}," getDatabaseForTenant",{"type":43,"tag":220,"props":1538,"children":1539},{"style":238},[1540],{"type":49,"value":286},{"type":43,"tag":220,"props":1542,"children":1543},{"style":289},[1544],{"type":49,"value":1183},{"type":43,"tag":220,"props":1546,"children":1547},{"style":238},[1548],{"type":49,"value":297},{"type":43,"tag":220,"props":1550,"children":1551},{"style":300},[1552],{"type":49,"value":303},{"type":43,"tag":220,"props":1554,"children":1555},{"style":238},[1556],{"type":49,"value":663},{"type":43,"tag":220,"props":1558,"children":1559},{"style":300},[1560],{"type":49,"value":1428},{"type":43,"tag":220,"props":1562,"children":1563},{"style":238},[1564],{"type":49,"value":332},{"type":43,"tag":220,"props":1566,"children":1567},{"class":222,"line":478},[1568,1572,1577,1581,1586,1590,1595,1599,1603,1607],{"type":43,"tag":220,"props":1569,"children":1570},{"style":226},[1571],{"type":49,"value":341},{"type":43,"tag":220,"props":1573,"children":1574},{"style":232},[1575],{"type":49,"value":1576}," dedicated",{"type":43,"tag":220,"props":1578,"children":1579},{"style":238},[1580],{"type":49,"value":351},{"type":43,"tag":220,"props":1582,"children":1583},{"style":232},[1584],{"type":49,"value":1585}," DEDICATED_TENANTS",{"type":43,"tag":220,"props":1587,"children":1588},{"style":238},[1589],{"type":49,"value":361},{"type":43,"tag":220,"props":1591,"children":1592},{"style":278},[1593],{"type":49,"value":1594},"get",{"type":43,"tag":220,"props":1596,"children":1597},{"style":369},[1598],{"type":49,"value":286},{"type":43,"tag":220,"props":1600,"children":1601},{"style":232},[1602],{"type":49,"value":1183},{"type":43,"tag":220,"props":1604,"children":1605},{"style":369},[1606],{"type":49,"value":327},{"type":43,"tag":220,"props":1608,"children":1609},{"style":238},[1610],{"type":49,"value":252},{"type":43,"tag":220,"props":1612,"children":1613},{"class":222,"line":584},[1614,1619,1623,1628,1633,1638,1642,1646],{"type":43,"tag":220,"props":1615,"children":1616},{"style":415},[1617],{"type":49,"value":1618},"  if",{"type":43,"tag":220,"props":1620,"children":1621},{"style":369},[1622],{"type":49,"value":782},{"type":43,"tag":220,"props":1624,"children":1625},{"style":232},[1626],{"type":49,"value":1627},"dedicated",{"type":43,"tag":220,"props":1629,"children":1630},{"style":369},[1631],{"type":49,"value":1632},") ",{"type":43,"tag":220,"props":1634,"children":1635},{"style":415},[1636],{"type":49,"value":1637},"return",{"type":43,"tag":220,"props":1639,"children":1640},{"style":232},[1641],{"type":49,"value":1576},{"type":43,"tag":220,"props":1643,"children":1644},{"style":238},[1645],{"type":49,"value":1139},{"type":43,"tag":220,"props":1647,"children":1648},{"style":622},[1649],{"type":49,"value":1650}," \u002F\u002F Hot tenant gets their own infrastructure\n",{"type":43,"tag":220,"props":1652,"children":1653},{"class":222,"line":601},[1654],{"type":43,"tag":220,"props":1655,"children":1656},{"emptyLinePlaceholder":259},[1657],{"type":49,"value":262},{"type":43,"tag":220,"props":1659,"children":1660},{"class":222,"line":610},[1661,1665,1670,1674,1679,1683,1687,1691,1696,1701],{"type":43,"tag":220,"props":1662,"children":1663},{"style":226},[1664],{"type":49,"value":341},{"type":43,"tag":220,"props":1666,"children":1667},{"style":232},[1668],{"type":49,"value":1669}," shardIndex",{"type":43,"tag":220,"props":1671,"children":1672},{"style":238},[1673],{"type":49,"value":351},{"type":43,"tag":220,"props":1675,"children":1676},{"style":278},[1677],{"type":49,"value":1678}," hash",{"type":43,"tag":220,"props":1680,"children":1681},{"style":369},[1682],{"type":49,"value":286},{"type":43,"tag":220,"props":1684,"children":1685},{"style":232},[1686],{"type":49,"value":1183},{"type":43,"tag":220,"props":1688,"children":1689},{"style":369},[1690],{"type":49,"value":1632},{"type":43,"tag":220,"props":1692,"children":1693},{"style":238},[1694],{"type":49,"value":1695},"%",{"type":43,"tag":220,"props":1697,"children":1698},{"style":232},[1699],{"type":49,"value":1700}," NUM_SHARED_SHARDS",{"type":43,"tag":220,"props":1702,"children":1703},{"style":238},[1704],{"type":49,"value":252},{"type":43,"tag":220,"props":1706,"children":1707},{"class":222,"line":618},[1708,1712,1717,1722,1727,1732],{"type":43,"tag":220,"props":1709,"children":1710},{"style":415},[1711],{"type":49,"value":1002},{"type":43,"tag":220,"props":1713,"children":1714},{"style":232},[1715],{"type":49,"value":1716}," sharedShards",{"type":43,"tag":220,"props":1718,"children":1719},{"style":369},[1720],{"type":49,"value":1721},"[",{"type":43,"tag":220,"props":1723,"children":1724},{"style":232},[1725],{"type":49,"value":1726},"shardIndex",{"type":43,"tag":220,"props":1728,"children":1729},{"style":369},[1730],{"type":49,"value":1731},"]",{"type":43,"tag":220,"props":1733,"children":1734},{"style":238},[1735],{"type":49,"value":252},{"type":43,"tag":220,"props":1737,"children":1738},{"class":222,"line":628},[1739],{"type":43,"tag":220,"props":1740,"children":1741},{"style":238},[1742],{"type":49,"value":607},{"type":43,"tag":52,"props":1744,"children":1745},{},[1746,1750],{"type":43,"tag":58,"props":1747,"children":1748},{},[1749],{"type":49,"value":1085},{"type":49,"value":1751}," Operational complexity -- you manage per-tenant infrastructure. But it completely isolates hot tenant load from everyone else. This is the standard pattern for enterprise SaaS at scale.",{"type":43,"tag":197,"props":1753,"children":1755},{"id":1754},"cache-layer-for-hot-reads",[1756],{"type":49,"value":1757},"Cache layer for hot reads",{"type":43,"tag":52,"props":1759,"children":1760},{},[1761],{"type":49,"value":1762},"When a key is read-hot (many reads, few writes), cache it aggressively.",{"type":43,"tag":209,"props":1764,"children":1766},{"className":211,"code":1765,"language":213,"meta":214,"style":214},"async function getLeaderboard(): Promise\u003CLeaderboardEntry[]> {\n  const cached = await cache.get(\"global-leaderboard\");\n  if (cached) return JSON.parse(cached);\n\n  \u002F\u002F Use stampede protection (see Thundering Herd skill)\n  const data = await fetchWithCoalescing(\"global-leaderboard\", () =>\n    db.query(\"SELECT * FROM leaderboard ORDER BY score DESC LIMIT 100\")\n  );\n\n  await cache.set(\"global-leaderboard\", JSON.stringify(data), { EX: 10 });\n  return data;\n}\n",[1767],{"type":43,"tag":130,"props":1768,"children":1769},{"__ignoreMap":214},[1770,1816,1874,1928,1935,1943,1997,2034,2045,2052,2152,2167],{"type":43,"tag":220,"props":1771,"children":1772},{"class":222,"line":30},[1773,1777,1781,1786,1791,1795,1799,1804,1808,1812],{"type":43,"tag":220,"props":1774,"children":1775},{"style":226},[1776],{"type":49,"value":270},{"type":43,"tag":220,"props":1778,"children":1779},{"style":226},[1780],{"type":49,"value":275},{"type":43,"tag":220,"props":1782,"children":1783},{"style":278},[1784],{"type":49,"value":1785}," getLeaderboard",{"type":43,"tag":220,"props":1787,"children":1788},{"style":238},[1789],{"type":49,"value":1790},"():",{"type":43,"tag":220,"props":1792,"children":1793},{"style":300},[1794],{"type":49,"value":668},{"type":43,"tag":220,"props":1796,"children":1797},{"style":238},[1798],{"type":49,"value":673},{"type":43,"tag":220,"props":1800,"children":1801},{"style":300},[1802],{"type":49,"value":1803},"LeaderboardEntry",{"type":43,"tag":220,"props":1805,"children":1806},{"style":232},[1807],{"type":49,"value":683},{"type":43,"tag":220,"props":1809,"children":1810},{"style":238},[1811],{"type":49,"value":688},{"type":43,"tag":220,"props":1813,"children":1814},{"style":238},[1815],{"type":49,"value":332},{"type":43,"tag":220,"props":1817,"children":1818},{"class":222,"line":255},[1819,1823,1828,1832,1836,1841,1845,1849,1853,1857,1862,1866,1870],{"type":43,"tag":220,"props":1820,"children":1821},{"style":226},[1822],{"type":49,"value":341},{"type":43,"tag":220,"props":1824,"children":1825},{"style":232},[1826],{"type":49,"value":1827}," cached",{"type":43,"tag":220,"props":1829,"children":1830},{"style":238},[1831],{"type":49,"value":351},{"type":43,"tag":220,"props":1833,"children":1834},{"style":415},[1835],{"type":49,"value":714},{"type":43,"tag":220,"props":1837,"children":1838},{"style":232},[1839],{"type":49,"value":1840}," cache",{"type":43,"tag":220,"props":1842,"children":1843},{"style":238},[1844],{"type":49,"value":361},{"type":43,"tag":220,"props":1846,"children":1847},{"style":278},[1848],{"type":49,"value":1594},{"type":43,"tag":220,"props":1850,"children":1851},{"style":369},[1852],{"type":49,"value":286},{"type":43,"tag":220,"props":1854,"children":1855},{"style":238},[1856],{"type":49,"value":470},{"type":43,"tag":220,"props":1858,"children":1859},{"style":462},[1860],{"type":49,"value":1861},"global-leaderboard",{"type":43,"tag":220,"props":1863,"children":1864},{"style":238},[1865],{"type":49,"value":470},{"type":43,"tag":220,"props":1867,"children":1868},{"style":369},[1869],{"type":49,"value":327},{"type":43,"tag":220,"props":1871,"children":1872},{"style":238},[1873],{"type":49,"value":252},{"type":43,"tag":220,"props":1875,"children":1876},{"class":222,"line":26},[1877,1881,1885,1890,1894,1898,1903,1907,1912,1916,1920,1924],{"type":43,"tag":220,"props":1878,"children":1879},{"style":415},[1880],{"type":49,"value":1618},{"type":43,"tag":220,"props":1882,"children":1883},{"style":369},[1884],{"type":49,"value":782},{"type":43,"tag":220,"props":1886,"children":1887},{"style":232},[1888],{"type":49,"value":1889},"cached",{"type":43,"tag":220,"props":1891,"children":1892},{"style":369},[1893],{"type":49,"value":1632},{"type":43,"tag":220,"props":1895,"children":1896},{"style":415},[1897],{"type":49,"value":1637},{"type":43,"tag":220,"props":1899,"children":1900},{"style":232},[1901],{"type":49,"value":1902}," JSON",{"type":43,"tag":220,"props":1904,"children":1905},{"style":238},[1906],{"type":49,"value":361},{"type":43,"tag":220,"props":1908,"children":1909},{"style":278},[1910],{"type":49,"value":1911},"parse",{"type":43,"tag":220,"props":1913,"children":1914},{"style":369},[1915],{"type":49,"value":286},{"type":43,"tag":220,"props":1917,"children":1918},{"style":232},[1919],{"type":49,"value":1889},{"type":43,"tag":220,"props":1921,"children":1922},{"style":369},[1923],{"type":49,"value":327},{"type":43,"tag":220,"props":1925,"children":1926},{"style":238},[1927],{"type":49,"value":252},{"type":43,"tag":220,"props":1929,"children":1930},{"class":222,"line":335},[1931],{"type":43,"tag":220,"props":1932,"children":1933},{"emptyLinePlaceholder":259},[1934],{"type":49,"value":262},{"type":43,"tag":220,"props":1936,"children":1937},{"class":222,"line":411},[1938],{"type":43,"tag":220,"props":1939,"children":1940},{"style":622},[1941],{"type":49,"value":1942},"  \u002F\u002F Use stampede protection (see Thundering Herd skill)\n",{"type":43,"tag":220,"props":1944,"children":1945},{"class":222,"line":444},[1946,1950,1955,1959,1963,1968,1972,1976,1980,1984,1988,1993],{"type":43,"tag":220,"props":1947,"children":1948},{"style":226},[1949],{"type":49,"value":341},{"type":43,"tag":220,"props":1951,"children":1952},{"style":232},[1953],{"type":49,"value":1954}," data",{"type":43,"tag":220,"props":1956,"children":1957},{"style":238},[1958],{"type":49,"value":351},{"type":43,"tag":220,"props":1960,"children":1961},{"style":415},[1962],{"type":49,"value":714},{"type":43,"tag":220,"props":1964,"children":1965},{"style":278},[1966],{"type":49,"value":1967}," fetchWithCoalescing",{"type":43,"tag":220,"props":1969,"children":1970},{"style":369},[1971],{"type":49,"value":286},{"type":43,"tag":220,"props":1973,"children":1974},{"style":238},[1975],{"type":49,"value":470},{"type":43,"tag":220,"props":1977,"children":1978},{"style":462},[1979],{"type":49,"value":1861},{"type":43,"tag":220,"props":1981,"children":1982},{"style":238},[1983],{"type":49,"value":470},{"type":43,"tag":220,"props":1985,"children":1986},{"style":238},[1987],{"type":49,"value":308},{"type":43,"tag":220,"props":1989,"children":1990},{"style":238},[1991],{"type":49,"value":1992}," ()",{"type":43,"tag":220,"props":1994,"children":1995},{"style":226},[1996],{"type":49,"value":805},{"type":43,"tag":220,"props":1998,"children":1999},{"class":222,"line":478},[2000,2005,2009,2013,2017,2021,2026,2030],{"type":43,"tag":220,"props":2001,"children":2002},{"style":232},[2003],{"type":49,"value":2004},"    db",{"type":43,"tag":220,"props":2006,"children":2007},{"style":238},[2008],{"type":49,"value":361},{"type":43,"tag":220,"props":2010,"children":2011},{"style":278},[2012],{"type":49,"value":823},{"type":43,"tag":220,"props":2014,"children":2015},{"style":369},[2016],{"type":49,"value":286},{"type":43,"tag":220,"props":2018,"children":2019},{"style":238},[2020],{"type":49,"value":470},{"type":43,"tag":220,"props":2022,"children":2023},{"style":462},[2024],{"type":49,"value":2025},"SELECT * FROM leaderboard ORDER BY score DESC LIMIT 100",{"type":43,"tag":220,"props":2027,"children":2028},{"style":238},[2029],{"type":49,"value":470},{"type":43,"tag":220,"props":2031,"children":2032},{"style":369},[2033],{"type":49,"value":971},{"type":43,"tag":220,"props":2035,"children":2036},{"class":222,"line":584},[2037,2041],{"type":43,"tag":220,"props":2038,"children":2039},{"style":369},[2040],{"type":49,"value":989},{"type":43,"tag":220,"props":2042,"children":2043},{"style":238},[2044],{"type":49,"value":252},{"type":43,"tag":220,"props":2046,"children":2047},{"class":222,"line":601},[2048],{"type":43,"tag":220,"props":2049,"children":2050},{"emptyLinePlaceholder":259},[2051],{"type":49,"value":262},{"type":43,"tag":220,"props":2053,"children":2054},{"class":222,"line":610},[2055,2059,2063,2067,2072,2076,2080,2084,2088,2092,2096,2100,2105,2109,2114,2118,2122,2126,2131,2135,2139,2144,2148],{"type":43,"tag":220,"props":2056,"children":2057},{"style":415},[2058],{"type":49,"value":418},{"type":43,"tag":220,"props":2060,"children":2061},{"style":232},[2062],{"type":49,"value":1840},{"type":43,"tag":220,"props":2064,"children":2065},{"style":238},[2066],{"type":49,"value":361},{"type":43,"tag":220,"props":2068,"children":2069},{"style":278},[2070],{"type":49,"value":2071},"set",{"type":43,"tag":220,"props":2073,"children":2074},{"style":369},[2075],{"type":49,"value":286},{"type":43,"tag":220,"props":2077,"children":2078},{"style":238},[2079],{"type":49,"value":470},{"type":43,"tag":220,"props":2081,"children":2082},{"style":462},[2083],{"type":49,"value":1861},{"type":43,"tag":220,"props":2085,"children":2086},{"style":238},[2087],{"type":49,"value":470},{"type":43,"tag":220,"props":2089,"children":2090},{"style":238},[2091],{"type":49,"value":308},{"type":43,"tag":220,"props":2093,"children":2094},{"style":232},[2095],{"type":49,"value":1902},{"type":43,"tag":220,"props":2097,"children":2098},{"style":238},[2099],{"type":49,"value":361},{"type":43,"tag":220,"props":2101,"children":2102},{"style":278},[2103],{"type":49,"value":2104},"stringify",{"type":43,"tag":220,"props":2106,"children":2107},{"style":369},[2108],{"type":49,"value":286},{"type":43,"tag":220,"props":2110,"children":2111},{"style":232},[2112],{"type":49,"value":2113},"data",{"type":43,"tag":220,"props":2115,"children":2116},{"style":369},[2117],{"type":49,"value":327},{"type":43,"tag":220,"props":2119,"children":2120},{"style":238},[2121],{"type":49,"value":308},{"type":43,"tag":220,"props":2123,"children":2124},{"style":238},[2125],{"type":49,"value":493},{"type":43,"tag":220,"props":2127,"children":2128},{"style":369},[2129],{"type":49,"value":2130}," EX",{"type":43,"tag":220,"props":2132,"children":2133},{"style":238},[2134],{"type":49,"value":297},{"type":43,"tag":220,"props":2136,"children":2137},{"style":244},[2138],{"type":49,"value":247},{"type":43,"tag":220,"props":2140,"children":2141},{"style":238},[2142],{"type":49,"value":2143}," }",{"type":43,"tag":220,"props":2145,"children":2146},{"style":369},[2147],{"type":49,"value":327},{"type":43,"tag":220,"props":2149,"children":2150},{"style":238},[2151],{"type":49,"value":252},{"type":43,"tag":220,"props":2153,"children":2154},{"class":222,"line":618},[2155,2159,2163],{"type":43,"tag":220,"props":2156,"children":2157},{"style":415},[2158],{"type":49,"value":1002},{"type":43,"tag":220,"props":2160,"children":2161},{"style":232},[2162],{"type":49,"value":1954},{"type":43,"tag":220,"props":2164,"children":2165},{"style":238},[2166],{"type":49,"value":252},{"type":43,"tag":220,"props":2168,"children":2169},{"class":222,"line":628},[2170],{"type":43,"tag":220,"props":2171,"children":2172},{"style":238},[2173],{"type":49,"value":607},{"type":43,"tag":52,"props":2175,"children":2176},{},[2177,2181],{"type":43,"tag":58,"props":2178,"children":2179},{},[2180],{"type":49,"value":1085},{"type":49,"value":2182}," Adds staleness (up to TTL seconds old). Doesn't help with write-hot partitions. Combine with stampede protection to avoid thundering herd when the cache expires.",{"type":43,"tag":197,"props":2184,"children":2186},{"id":2185},"higher-cardinality-kafka-partition-keys",[2187],{"type":49,"value":2188},"Higher-cardinality Kafka partition keys",{"type":43,"tag":209,"props":2190,"children":2192},{"className":211,"code":2191,"language":213,"meta":214,"style":214},"\u002F\u002F BAD: country code has ~200 values, US dominates\nawait producer.send({\n  topic: \"user-events\",\n  messages: [{ key: user.countryCode, value: JSON.stringify(event) }],\n});\n\n\u002F\u002F GOOD: user_id has millions of values, distributes evenly\nawait producer.send({\n  topic: \"user-events\",\n  messages: [{ key: user.id, value: JSON.stringify(event) }],\n});\n\n\u002F\u002F GOOD: for a known hot key, add a random suffix\nconst key = isHotUser(user.id)\n  ? `${user.id}-${Math.floor(Math.random() * 8)}` \u002F\u002F Spread across 8 partitions\n  : user.id;\n",[2193],{"type":43,"tag":130,"props":2194,"children":2195},{"__ignoreMap":214},[2196,2204,2234,2263,2349,2364,2371,2379,2406,2433,2513,2528,2535,2543,2578,2667],{"type":43,"tag":220,"props":2197,"children":2198},{"class":222,"line":30},[2199],{"type":43,"tag":220,"props":2200,"children":2201},{"style":622},[2202],{"type":49,"value":2203},"\u002F\u002F BAD: country code has ~200 values, US dominates\n",{"type":43,"tag":220,"props":2205,"children":2206},{"class":222,"line":255},[2207,2212,2217,2221,2226,2230],{"type":43,"tag":220,"props":2208,"children":2209},{"style":415},[2210],{"type":49,"value":2211},"await",{"type":43,"tag":220,"props":2213,"children":2214},{"style":232},[2215],{"type":49,"value":2216}," producer",{"type":43,"tag":220,"props":2218,"children":2219},{"style":238},[2220],{"type":49,"value":361},{"type":43,"tag":220,"props":2222,"children":2223},{"style":278},[2224],{"type":49,"value":2225},"send",{"type":43,"tag":220,"props":2227,"children":2228},{"style":232},[2229],{"type":49,"value":286},{"type":43,"tag":220,"props":2231,"children":2232},{"style":238},[2233],{"type":49,"value":441},{"type":43,"tag":220,"props":2235,"children":2236},{"class":222,"line":26},[2237,2242,2246,2250,2255,2259],{"type":43,"tag":220,"props":2238,"children":2239},{"style":369},[2240],{"type":49,"value":2241},"  topic",{"type":43,"tag":220,"props":2243,"children":2244},{"style":238},[2245],{"type":49,"value":297},{"type":43,"tag":220,"props":2247,"children":2248},{"style":238},[2249],{"type":49,"value":459},{"type":43,"tag":220,"props":2251,"children":2252},{"style":462},[2253],{"type":49,"value":2254},"user-events",{"type":43,"tag":220,"props":2256,"children":2257},{"style":238},[2258],{"type":49,"value":470},{"type":43,"tag":220,"props":2260,"children":2261},{"style":238},[2262],{"type":49,"value":475},{"type":43,"tag":220,"props":2264,"children":2265},{"class":222,"line":335},[2266,2271,2275,2280,2284,2289,2293,2298,2302,2307,2311,2316,2320,2324,2328,2332,2337,2341,2345],{"type":43,"tag":220,"props":2267,"children":2268},{"style":369},[2269],{"type":49,"value":2270},"  messages",{"type":43,"tag":220,"props":2272,"children":2273},{"style":238},[2274],{"type":49,"value":297},{"type":43,"tag":220,"props":2276,"children":2277},{"style":232},[2278],{"type":49,"value":2279}," [",{"type":43,"tag":220,"props":2281,"children":2282},{"style":238},[2283],{"type":49,"value":759},{"type":43,"tag":220,"props":2285,"children":2286},{"style":369},[2287],{"type":49,"value":2288}," key",{"type":43,"tag":220,"props":2290,"children":2291},{"style":238},[2292],{"type":49,"value":297},{"type":43,"tag":220,"props":2294,"children":2295},{"style":232},[2296],{"type":49,"value":2297}," user",{"type":43,"tag":220,"props":2299,"children":2300},{"style":238},[2301],{"type":49,"value":361},{"type":43,"tag":220,"props":2303,"children":2304},{"style":232},[2305],{"type":49,"value":2306},"countryCode",{"type":43,"tag":220,"props":2308,"children":2309},{"style":238},[2310],{"type":49,"value":308},{"type":43,"tag":220,"props":2312,"children":2313},{"style":369},[2314],{"type":49,"value":2315}," value",{"type":43,"tag":220,"props":2317,"children":2318},{"style":238},[2319],{"type":49,"value":297},{"type":43,"tag":220,"props":2321,"children":2322},{"style":232},[2323],{"type":49,"value":1902},{"type":43,"tag":220,"props":2325,"children":2326},{"style":238},[2327],{"type":49,"value":361},{"type":43,"tag":220,"props":2329,"children":2330},{"style":278},[2331],{"type":49,"value":2104},{"type":43,"tag":220,"props":2333,"children":2334},{"style":232},[2335],{"type":49,"value":2336},"(event) ",{"type":43,"tag":220,"props":2338,"children":2339},{"style":238},[2340],{"type":49,"value":516},{"type":43,"tag":220,"props":2342,"children":2343},{"style":232},[2344],{"type":49,"value":1731},{"type":43,"tag":220,"props":2346,"children":2347},{"style":238},[2348],{"type":49,"value":475},{"type":43,"tag":220,"props":2350,"children":2351},{"class":222,"line":411},[2352,2356,2360],{"type":43,"tag":220,"props":2353,"children":2354},{"style":238},[2355],{"type":49,"value":516},{"type":43,"tag":220,"props":2357,"children":2358},{"style":232},[2359],{"type":49,"value":327},{"type":43,"tag":220,"props":2361,"children":2362},{"style":238},[2363],{"type":49,"value":252},{"type":43,"tag":220,"props":2365,"children":2366},{"class":222,"line":444},[2367],{"type":43,"tag":220,"props":2368,"children":2369},{"emptyLinePlaceholder":259},[2370],{"type":49,"value":262},{"type":43,"tag":220,"props":2372,"children":2373},{"class":222,"line":478},[2374],{"type":43,"tag":220,"props":2375,"children":2376},{"style":622},[2377],{"type":49,"value":2378},"\u002F\u002F GOOD: user_id has millions of values, distributes evenly\n",{"type":43,"tag":220,"props":2380,"children":2381},{"class":222,"line":584},[2382,2386,2390,2394,2398,2402],{"type":43,"tag":220,"props":2383,"children":2384},{"style":415},[2385],{"type":49,"value":2211},{"type":43,"tag":220,"props":2387,"children":2388},{"style":232},[2389],{"type":49,"value":2216},{"type":43,"tag":220,"props":2391,"children":2392},{"style":238},[2393],{"type":49,"value":361},{"type":43,"tag":220,"props":2395,"children":2396},{"style":278},[2397],{"type":49,"value":2225},{"type":43,"tag":220,"props":2399,"children":2400},{"style":232},[2401],{"type":49,"value":286},{"type":43,"tag":220,"props":2403,"children":2404},{"style":238},[2405],{"type":49,"value":441},{"type":43,"tag":220,"props":2407,"children":2408},{"class":222,"line":601},[2409,2413,2417,2421,2425,2429],{"type":43,"tag":220,"props":2410,"children":2411},{"style":369},[2412],{"type":49,"value":2241},{"type":43,"tag":220,"props":2414,"children":2415},{"style":238},[2416],{"type":49,"value":297},{"type":43,"tag":220,"props":2418,"children":2419},{"style":238},[2420],{"type":49,"value":459},{"type":43,"tag":220,"props":2422,"children":2423},{"style":462},[2424],{"type":49,"value":2254},{"type":43,"tag":220,"props":2426,"children":2427},{"style":238},[2428],{"type":49,"value":470},{"type":43,"tag":220,"props":2430,"children":2431},{"style":238},[2432],{"type":49,"value":475},{"type":43,"tag":220,"props":2434,"children":2435},{"class":222,"line":610},[2436,2440,2444,2448,2452,2456,2460,2464,2468,2473,2477,2481,2485,2489,2493,2497,2501,2505,2509],{"type":43,"tag":220,"props":2437,"children":2438},{"style":369},[2439],{"type":49,"value":2270},{"type":43,"tag":220,"props":2441,"children":2442},{"style":238},[2443],{"type":49,"value":297},{"type":43,"tag":220,"props":2445,"children":2446},{"style":232},[2447],{"type":49,"value":2279},{"type":43,"tag":220,"props":2449,"children":2450},{"style":238},[2451],{"type":49,"value":759},{"type":43,"tag":220,"props":2453,"children":2454},{"style":369},[2455],{"type":49,"value":2288},{"type":43,"tag":220,"props":2457,"children":2458},{"style":238},[2459],{"type":49,"value":297},{"type":43,"tag":220,"props":2461,"children":2462},{"style":232},[2463],{"type":49,"value":2297},{"type":43,"tag":220,"props":2465,"children":2466},{"style":238},[2467],{"type":49,"value":361},{"type":43,"tag":220,"props":2469,"children":2470},{"style":232},[2471],{"type":49,"value":2472},"id",{"type":43,"tag":220,"props":2474,"children":2475},{"style":238},[2476],{"type":49,"value":308},{"type":43,"tag":220,"props":2478,"children":2479},{"style":369},[2480],{"type":49,"value":2315},{"type":43,"tag":220,"props":2482,"children":2483},{"style":238},[2484],{"type":49,"value":297},{"type":43,"tag":220,"props":2486,"children":2487},{"style":232},[2488],{"type":49,"value":1902},{"type":43,"tag":220,"props":2490,"children":2491},{"style":238},[2492],{"type":49,"value":361},{"type":43,"tag":220,"props":2494,"children":2495},{"style":278},[2496],{"type":49,"value":2104},{"type":43,"tag":220,"props":2498,"children":2499},{"style":232},[2500],{"type":49,"value":2336},{"type":43,"tag":220,"props":2502,"children":2503},{"style":238},[2504],{"type":49,"value":516},{"type":43,"tag":220,"props":2506,"children":2507},{"style":232},[2508],{"type":49,"value":1731},{"type":43,"tag":220,"props":2510,"children":2511},{"style":238},[2512],{"type":49,"value":475},{"type":43,"tag":220,"props":2514,"children":2515},{"class":222,"line":618},[2516,2520,2524],{"type":43,"tag":220,"props":2517,"children":2518},{"style":238},[2519],{"type":49,"value":516},{"type":43,"tag":220,"props":2521,"children":2522},{"style":232},[2523],{"type":49,"value":327},{"type":43,"tag":220,"props":2525,"children":2526},{"style":238},[2527],{"type":49,"value":252},{"type":43,"tag":220,"props":2529,"children":2530},{"class":222,"line":628},[2531],{"type":43,"tag":220,"props":2532,"children":2533},{"emptyLinePlaceholder":259},[2534],{"type":49,"value":262},{"type":43,"tag":220,"props":2536,"children":2537},{"class":222,"line":695},[2538],{"type":43,"tag":220,"props":2539,"children":2540},{"style":622},[2541],{"type":49,"value":2542},"\u002F\u002F GOOD: for a known hot key, add a random suffix\n",{"type":43,"tag":220,"props":2544,"children":2545},{"class":222,"line":735},[2546,2550,2555,2559,2564,2569,2573],{"type":43,"tag":220,"props":2547,"children":2548},{"style":226},[2549],{"type":49,"value":229},{"type":43,"tag":220,"props":2551,"children":2552},{"style":232},[2553],{"type":49,"value":2554}," key ",{"type":43,"tag":220,"props":2556,"children":2557},{"style":238},[2558],{"type":49,"value":241},{"type":43,"tag":220,"props":2560,"children":2561},{"style":278},[2562],{"type":49,"value":2563}," isHotUser",{"type":43,"tag":220,"props":2565,"children":2566},{"style":232},[2567],{"type":49,"value":2568},"(user",{"type":43,"tag":220,"props":2570,"children":2571},{"style":238},[2572],{"type":49,"value":361},{"type":43,"tag":220,"props":2574,"children":2575},{"style":232},[2576],{"type":49,"value":2577},"id)\n",{"type":43,"tag":220,"props":2579,"children":2580},{"class":222,"line":808},[2581,2586,2590,2595,2599,2603,2607,2612,2616,2620,2624,2628,2633,2637,2641,2645,2649,2654,2658,2662],{"type":43,"tag":220,"props":2582,"children":2583},{"style":238},[2584],{"type":49,"value":2585},"  ?",{"type":43,"tag":220,"props":2587,"children":2588},{"style":238},[2589],{"type":49,"value":507},{"type":43,"tag":220,"props":2591,"children":2592},{"style":232},[2593],{"type":49,"value":2594},"user",{"type":43,"tag":220,"props":2596,"children":2597},{"style":238},[2598],{"type":49,"value":361},{"type":43,"tag":220,"props":2600,"children":2601},{"style":232},[2602],{"type":49,"value":2472},{"type":43,"tag":220,"props":2604,"children":2605},{"style":238},[2606],{"type":49,"value":516},{"type":43,"tag":220,"props":2608,"children":2609},{"style":462},[2610],{"type":49,"value":2611},"-",{"type":43,"tag":220,"props":2613,"children":2614},{"style":238},[2615],{"type":49,"value":526},{"type":43,"tag":220,"props":2617,"children":2618},{"style":232},[2619],{"type":49,"value":376},{"type":43,"tag":220,"props":2621,"children":2622},{"style":238},[2623],{"type":49,"value":361},{"type":43,"tag":220,"props":2625,"children":2626},{"style":278},[2627],{"type":49,"value":366},{"type":43,"tag":220,"props":2629,"children":2630},{"style":232},[2631],{"type":49,"value":2632},"(Math",{"type":43,"tag":220,"props":2634,"children":2635},{"style":238},[2636],{"type":49,"value":361},{"type":43,"tag":220,"props":2638,"children":2639},{"style":278},[2640],{"type":49,"value":385},{"type":43,"tag":220,"props":2642,"children":2643},{"style":232},[2644],{"type":49,"value":390},{"type":43,"tag":220,"props":2646,"children":2647},{"style":238},[2648],{"type":49,"value":395},{"type":43,"tag":220,"props":2650,"children":2651},{"style":244},[2652],{"type":49,"value":2653}," 8",{"type":43,"tag":220,"props":2655,"children":2656},{"style":232},[2657],{"type":49,"value":327},{"type":43,"tag":220,"props":2659,"children":2660},{"style":238},[2661],{"type":49,"value":536},{"type":43,"tag":220,"props":2663,"children":2664},{"style":622},[2665],{"type":49,"value":2666}," \u002F\u002F Spread across 8 partitions\n",{"type":43,"tag":220,"props":2668,"children":2669},{"class":222,"line":834},[2670,2675,2679,2683,2687],{"type":43,"tag":220,"props":2671,"children":2672},{"style":238},[2673],{"type":49,"value":2674},"  :",{"type":43,"tag":220,"props":2676,"children":2677},{"style":232},[2678],{"type":49,"value":2297},{"type":43,"tag":220,"props":2680,"children":2681},{"style":238},[2682],{"type":49,"value":361},{"type":43,"tag":220,"props":2684,"children":2685},{"style":232},[2686],{"type":49,"value":2472},{"type":43,"tag":220,"props":2688,"children":2689},{"style":238},[2690],{"type":49,"value":252},{"type":43,"tag":52,"props":2692,"children":2693},{},[2694,2698],{"type":43,"tag":58,"props":2695,"children":2696},{},[2697],{"type":49,"value":1085},{"type":49,"value":2699}," Changing the partition key changes message ordering guarantees. Messages for the same user may land on different partitions with the random suffix, losing per-user ordering. Only use the suffix for keys where ordering doesn't matter.",{"type":43,"tag":197,"props":2701,"children":2703},{"id":2702},"per-partition-monitoring",[2704],{"type":49,"value":2705},"Per-partition monitoring",{"type":43,"tag":209,"props":2707,"children":2709},{"className":211,"code":2708,"language":213,"meta":214,"style":214},"function recordPartitionAccess(partitionKey: string, operation: \"read\" | \"write\") {\n  metrics.increment(\"partition.operations\", { partition: partitionKey, operation });\n}\n\n\u002F\u002F Alert when:\n\u002F\u002F - One partition exceeds 3x the average operations\n\u002F\u002F - Partition utilization exceeds 80% of its throughput limit\n\u002F\u002F - Consumer lag on one Kafka partition grows while others are stable\n",[2710],{"type":43,"tag":130,"props":2711,"children":2712},{"__ignoreMap":214},[2713,2794,2870,2877,2884,2892,2900,2908],{"type":43,"tag":220,"props":2714,"children":2715},{"class":222,"line":30},[2716,2720,2725,2729,2734,2738,2742,2746,2751,2755,2759,2764,2768,2773,2777,2782,2786,2790],{"type":43,"tag":220,"props":2717,"children":2718},{"style":226},[2719],{"type":49,"value":1531},{"type":43,"tag":220,"props":2721,"children":2722},{"style":278},[2723],{"type":49,"value":2724}," recordPartitionAccess",{"type":43,"tag":220,"props":2726,"children":2727},{"style":238},[2728],{"type":49,"value":286},{"type":43,"tag":220,"props":2730,"children":2731},{"style":289},[2732],{"type":49,"value":2733},"partitionKey",{"type":43,"tag":220,"props":2735,"children":2736},{"style":238},[2737],{"type":49,"value":297},{"type":43,"tag":220,"props":2739,"children":2740},{"style":300},[2741],{"type":49,"value":303},{"type":43,"tag":220,"props":2743,"children":2744},{"style":238},[2745],{"type":49,"value":308},{"type":43,"tag":220,"props":2747,"children":2748},{"style":289},[2749],{"type":49,"value":2750}," operation",{"type":43,"tag":220,"props":2752,"children":2753},{"style":238},[2754],{"type":49,"value":297},{"type":43,"tag":220,"props":2756,"children":2757},{"style":238},[2758],{"type":49,"value":459},{"type":43,"tag":220,"props":2760,"children":2761},{"style":462},[2762],{"type":49,"value":2763},"read",{"type":43,"tag":220,"props":2765,"children":2766},{"style":238},[2767],{"type":49,"value":470},{"type":43,"tag":220,"props":2769,"children":2770},{"style":238},[2771],{"type":49,"value":2772}," |",{"type":43,"tag":220,"props":2774,"children":2775},{"style":238},[2776],{"type":49,"value":459},{"type":43,"tag":220,"props":2778,"children":2779},{"style":462},[2780],{"type":49,"value":2781},"write",{"type":43,"tag":220,"props":2783,"children":2784},{"style":238},[2785],{"type":49,"value":470},{"type":43,"tag":220,"props":2787,"children":2788},{"style":238},[2789],{"type":49,"value":327},{"type":43,"tag":220,"props":2791,"children":2792},{"style":238},[2793],{"type":49,"value":332},{"type":43,"tag":220,"props":2795,"children":2796},{"class":222,"line":255},[2797,2802,2806,2811,2815,2819,2824,2828,2832,2836,2841,2845,2850,2854,2858,2862,2866],{"type":43,"tag":220,"props":2798,"children":2799},{"style":232},[2800],{"type":49,"value":2801},"  metrics",{"type":43,"tag":220,"props":2803,"children":2804},{"style":238},[2805],{"type":49,"value":361},{"type":43,"tag":220,"props":2807,"children":2808},{"style":278},[2809],{"type":49,"value":2810},"increment",{"type":43,"tag":220,"props":2812,"children":2813},{"style":369},[2814],{"type":49,"value":286},{"type":43,"tag":220,"props":2816,"children":2817},{"style":238},[2818],{"type":49,"value":470},{"type":43,"tag":220,"props":2820,"children":2821},{"style":462},[2822],{"type":49,"value":2823},"partition.operations",{"type":43,"tag":220,"props":2825,"children":2826},{"style":238},[2827],{"type":49,"value":470},{"type":43,"tag":220,"props":2829,"children":2830},{"style":238},[2831],{"type":49,"value":308},{"type":43,"tag":220,"props":2833,"children":2834},{"style":238},[2835],{"type":49,"value":493},{"type":43,"tag":220,"props":2837,"children":2838},{"style":369},[2839],{"type":49,"value":2840}," partition",{"type":43,"tag":220,"props":2842,"children":2843},{"style":238},[2844],{"type":49,"value":297},{"type":43,"tag":220,"props":2846,"children":2847},{"style":232},[2848],{"type":49,"value":2849}," partitionKey",{"type":43,"tag":220,"props":2851,"children":2852},{"style":238},[2853],{"type":49,"value":308},{"type":43,"tag":220,"props":2855,"children":2856},{"style":232},[2857],{"type":49,"value":2750},{"type":43,"tag":220,"props":2859,"children":2860},{"style":238},[2861],{"type":49,"value":2143},{"type":43,"tag":220,"props":2863,"children":2864},{"style":369},[2865],{"type":49,"value":327},{"type":43,"tag":220,"props":2867,"children":2868},{"style":238},[2869],{"type":49,"value":252},{"type":43,"tag":220,"props":2871,"children":2872},{"class":222,"line":26},[2873],{"type":43,"tag":220,"props":2874,"children":2875},{"style":238},[2876],{"type":49,"value":607},{"type":43,"tag":220,"props":2878,"children":2879},{"class":222,"line":335},[2880],{"type":43,"tag":220,"props":2881,"children":2882},{"emptyLinePlaceholder":259},[2883],{"type":49,"value":262},{"type":43,"tag":220,"props":2885,"children":2886},{"class":222,"line":411},[2887],{"type":43,"tag":220,"props":2888,"children":2889},{"style":622},[2890],{"type":49,"value":2891},"\u002F\u002F Alert when:\n",{"type":43,"tag":220,"props":2893,"children":2894},{"class":222,"line":444},[2895],{"type":43,"tag":220,"props":2896,"children":2897},{"style":622},[2898],{"type":49,"value":2899},"\u002F\u002F - One partition exceeds 3x the average operations\n",{"type":43,"tag":220,"props":2901,"children":2902},{"class":222,"line":478},[2903],{"type":43,"tag":220,"props":2904,"children":2905},{"style":622},[2906],{"type":49,"value":2907},"\u002F\u002F - Partition utilization exceeds 80% of its throughput limit\n",{"type":43,"tag":220,"props":2909,"children":2910},{"class":222,"line":584},[2911],{"type":43,"tag":220,"props":2912,"children":2913},{"style":622},[2914],{"type":49,"value":2915},"\u002F\u002F - Consumer lag on one Kafka partition grows while others are stable\n",{"type":43,"tag":52,"props":2917,"children":2918},{},[2919],{"type":49,"value":2920},"This is not optional. Without per-partition metrics, you won't know a partition is hot until users report errors or the system pages you.",{"type":43,"tag":64,"props":2922,"children":2924},{"id":2923},"the-readwrite-tradeoff",[2925],{"type":49,"value":2926},"The Read\u002FWrite Tradeoff",{"type":43,"tag":52,"props":2928,"children":2929},{},[2930],{"type":49,"value":2931},"Every hot partition fix has a read\u002Fwrite tradeoff:",{"type":43,"tag":2933,"props":2934,"children":2935},"table",{},[2936,2965],{"type":43,"tag":2937,"props":2938,"children":2939},"thead",{},[2940],{"type":43,"tag":2941,"props":2942,"children":2943},"tr",{},[2944,2950,2955,2960],{"type":43,"tag":2945,"props":2946,"children":2947},"th",{},[2948],{"type":49,"value":2949},"Technique",{"type":43,"tag":2945,"props":2951,"children":2952},{},[2953],{"type":49,"value":2954},"Writes",{"type":43,"tag":2945,"props":2956,"children":2957},{},[2958],{"type":49,"value":2959},"Reads",{"type":43,"tag":2945,"props":2961,"children":2962},{},[2963],{"type":49,"value":2964},"Best for",{"type":43,"tag":2966,"props":2967,"children":2968},"tbody",{},[2969,2993,3016,3038],{"type":43,"tag":2941,"props":2970,"children":2971},{},[2972,2978,2983,2988],{"type":43,"tag":2973,"props":2974,"children":2975},"td",{},[2976],{"type":49,"value":2977},"Random suffix sharding",{"type":43,"tag":2973,"props":2979,"children":2980},{},[2981],{"type":49,"value":2982},"Distributed perfectly",{"type":43,"tag":2973,"props":2984,"children":2985},{},[2986],{"type":49,"value":2987},"Scatter-gather (slower, costlier)",{"type":43,"tag":2973,"props":2989,"children":2990},{},[2991],{"type":49,"value":2992},"Write-heavy hot keys",{"type":43,"tag":2941,"props":2994,"children":2995},{},[2996,3001,3006,3011],{"type":43,"tag":2973,"props":2997,"children":2998},{},[2999],{"type":49,"value":3000},"Caching",{"type":43,"tag":2973,"props":3002,"children":3003},{},[3004],{"type":49,"value":3005},"Unchanged",{"type":43,"tag":2973,"props":3007,"children":3008},{},[3009],{"type":49,"value":3010},"Absorbed by cache",{"type":43,"tag":2973,"props":3012,"children":3013},{},[3014],{"type":49,"value":3015},"Read-heavy hot keys",{"type":43,"tag":2941,"props":3017,"children":3018},{},[3019,3024,3029,3033],{"type":43,"tag":2973,"props":3020,"children":3021},{},[3022],{"type":49,"value":3023},"Dedicated infrastructure",{"type":43,"tag":2973,"props":3025,"children":3026},{},[3027],{"type":49,"value":3028},"Isolated",{"type":43,"tag":2973,"props":3030,"children":3031},{},[3032],{"type":49,"value":3028},{"type":43,"tag":2973,"props":3034,"children":3035},{},[3036],{"type":49,"value":3037},"Known hot tenants",{"type":43,"tag":2941,"props":3039,"children":3040},{},[3041,3046,3051,3056],{"type":43,"tag":2973,"props":3042,"children":3043},{},[3044],{"type":49,"value":3045},"Composite keys",{"type":43,"tag":2973,"props":3047,"children":3048},{},[3049],{"type":49,"value":3050},"Spread across dimensions",{"type":43,"tag":2973,"props":3052,"children":3053},{},[3054],{"type":49,"value":3055},"Must know the dimension to query",{"type":43,"tag":2973,"props":3057,"children":3058},{},[3059],{"type":49,"value":3060},"Mixed workloads",{"type":43,"tag":52,"props":3062,"children":3063},{},[3064],{"type":49,"value":3065},"There is no technique that makes both reads and writes better. You're always trading one for the other.",{"type":43,"tag":64,"props":3067,"children":3069},{"id":3068},"anti-patterns",[3070],{"type":49,"value":3071},"Anti-Patterns",{"type":43,"tag":209,"props":3073,"children":3075},{"className":211,"code":3074,"language":213,"meta":214,"style":214},"\u002F\u002F Date partition for writes: today gets ALL writes\nconst pk = new Date().toISOString().split(\"T\")[0]; \u002F\u002F \"2024-01-15\"\n\n\u002F\u002F Low-cardinality Kafka key: US gets 50% of messages\nmessages: [{ key: user.countryCode, value: event }]\n\n\u002F\u002F Single global DynamoDB key: one partition handles all reads\nKeyConditionExpression: \"pk = :pk\", { \":pk\": \"global-config\" }\n\n\u002F\u002F Naive tenant sharding: enterprise tenant overloads one shard\nconst shard = hash(tenantId) % NUM_SHARDS;\n\n\u002F\u002F No per-partition monitoring: blind to imbalance\n\u002F\u002F You find out when users report errors, not from metrics\n",[3076],{"type":43,"tag":130,"props":3077,"children":3078},{"__ignoreMap":214},[3079,3087,3174,3181,3189,3255,3262,3270,3336,3343,3351,3389,3396,3404],{"type":43,"tag":220,"props":3080,"children":3081},{"class":222,"line":30},[3082],{"type":43,"tag":220,"props":3083,"children":3084},{"style":622},[3085],{"type":49,"value":3086},"\u002F\u002F Date partition for writes: today gets ALL writes\n",{"type":43,"tag":220,"props":3088,"children":3089},{"class":222,"line":255},[3090,3094,3098,3102,3106,3110,3114,3118,3122,3126,3130,3135,3139,3143,3148,3152,3157,3161,3165,3169],{"type":43,"tag":220,"props":3091,"children":3092},{"style":226},[3093],{"type":49,"value":229},{"type":43,"tag":220,"props":3095,"children":3096},{"style":232},[3097],{"type":49,"value":1125},{"type":43,"tag":220,"props":3099,"children":3100},{"style":238},[3101],{"type":49,"value":241},{"type":43,"tag":220,"props":3103,"children":3104},{"style":238},[3105],{"type":49,"value":1252},{"type":43,"tag":220,"props":3107,"children":3108},{"style":278},[3109],{"type":49,"value":1257},{"type":43,"tag":220,"props":3111,"children":3112},{"style":232},[3113],{"type":49,"value":1262},{"type":43,"tag":220,"props":3115,"children":3116},{"style":238},[3117],{"type":49,"value":361},{"type":43,"tag":220,"props":3119,"children":3120},{"style":278},[3121],{"type":49,"value":1271},{"type":43,"tag":220,"props":3123,"children":3124},{"style":232},[3125],{"type":49,"value":1262},{"type":43,"tag":220,"props":3127,"children":3128},{"style":238},[3129],{"type":49,"value":361},{"type":43,"tag":220,"props":3131,"children":3132},{"style":278},[3133],{"type":49,"value":3134},"split",{"type":43,"tag":220,"props":3136,"children":3137},{"style":232},[3138],{"type":49,"value":286},{"type":43,"tag":220,"props":3140,"children":3141},{"style":238},[3142],{"type":49,"value":470},{"type":43,"tag":220,"props":3144,"children":3145},{"style":462},[3146],{"type":49,"value":3147},"T",{"type":43,"tag":220,"props":3149,"children":3150},{"style":238},[3151],{"type":49,"value":470},{"type":43,"tag":220,"props":3153,"children":3154},{"style":232},[3155],{"type":49,"value":3156},")[",{"type":43,"tag":220,"props":3158,"children":3159},{"style":244},[3160],{"type":49,"value":1293},{"type":43,"tag":220,"props":3162,"children":3163},{"style":232},[3164],{"type":49,"value":1731},{"type":43,"tag":220,"props":3166,"children":3167},{"style":238},[3168],{"type":49,"value":1139},{"type":43,"tag":220,"props":3170,"children":3171},{"style":622},[3172],{"type":49,"value":3173}," \u002F\u002F \"2024-01-15\"\n",{"type":43,"tag":220,"props":3175,"children":3176},{"class":222,"line":26},[3177],{"type":43,"tag":220,"props":3178,"children":3179},{"emptyLinePlaceholder":259},[3180],{"type":49,"value":262},{"type":43,"tag":220,"props":3182,"children":3183},{"class":222,"line":335},[3184],{"type":43,"tag":220,"props":3185,"children":3186},{"style":622},[3187],{"type":49,"value":3188},"\u002F\u002F Low-cardinality Kafka key: US gets 50% of messages\n",{"type":43,"tag":220,"props":3190,"children":3191},{"class":222,"line":411},[3192,3197,3201,3205,3209,3213,3217,3221,3225,3229,3233,3237,3241,3246,3250],{"type":43,"tag":220,"props":3193,"children":3194},{"style":300},[3195],{"type":49,"value":3196},"messages",{"type":43,"tag":220,"props":3198,"children":3199},{"style":238},[3200],{"type":49,"value":297},{"type":43,"tag":220,"props":3202,"children":3203},{"style":232},[3204],{"type":49,"value":2279},{"type":43,"tag":220,"props":3206,"children":3207},{"style":238},[3208],{"type":49,"value":759},{"type":43,"tag":220,"props":3210,"children":3211},{"style":369},[3212],{"type":49,"value":2288},{"type":43,"tag":220,"props":3214,"children":3215},{"style":238},[3216],{"type":49,"value":297},{"type":43,"tag":220,"props":3218,"children":3219},{"style":232},[3220],{"type":49,"value":2297},{"type":43,"tag":220,"props":3222,"children":3223},{"style":238},[3224],{"type":49,"value":361},{"type":43,"tag":220,"props":3226,"children":3227},{"style":232},[3228],{"type":49,"value":2306},{"type":43,"tag":220,"props":3230,"children":3231},{"style":238},[3232],{"type":49,"value":308},{"type":43,"tag":220,"props":3234,"children":3235},{"style":369},[3236],{"type":49,"value":2315},{"type":43,"tag":220,"props":3238,"children":3239},{"style":238},[3240],{"type":49,"value":297},{"type":43,"tag":220,"props":3242,"children":3243},{"style":232},[3244],{"type":49,"value":3245}," event ",{"type":43,"tag":220,"props":3247,"children":3248},{"style":238},[3249],{"type":49,"value":516},{"type":43,"tag":220,"props":3251,"children":3252},{"style":232},[3253],{"type":49,"value":3254},"]\n",{"type":43,"tag":220,"props":3256,"children":3257},{"class":222,"line":444},[3258],{"type":43,"tag":220,"props":3259,"children":3260},{"emptyLinePlaceholder":259},[3261],{"type":49,"value":262},{"type":43,"tag":220,"props":3263,"children":3264},{"class":222,"line":478},[3265],{"type":43,"tag":220,"props":3266,"children":3267},{"style":622},[3268],{"type":49,"value":3269},"\u002F\u002F Single global DynamoDB key: one partition handles all reads\n",{"type":43,"tag":220,"props":3271,"children":3272},{"class":222,"line":584},[3273,3278,3282,3286,3290,3294,3298,3302,3306,3310,3314,3318,3322,3327,3331],{"type":43,"tag":220,"props":3274,"children":3275},{"style":300},[3276],{"type":49,"value":3277},"KeyConditionExpression",{"type":43,"tag":220,"props":3279,"children":3280},{"style":238},[3281],{"type":49,"value":297},{"type":43,"tag":220,"props":3283,"children":3284},{"style":238},[3285],{"type":49,"value":459},{"type":43,"tag":220,"props":3287,"children":3288},{"style":462},[3289],{"type":49,"value":882},{"type":43,"tag":220,"props":3291,"children":3292},{"style":238},[3293],{"type":49,"value":470},{"type":43,"tag":220,"props":3295,"children":3296},{"style":238},[3297],{"type":49,"value":308},{"type":43,"tag":220,"props":3299,"children":3300},{"style":238},[3301],{"type":49,"value":493},{"type":43,"tag":220,"props":3303,"children":3304},{"style":238},[3305],{"type":49,"value":459},{"type":43,"tag":220,"props":3307,"children":3308},{"style":369},[3309],{"type":49,"value":916},{"type":43,"tag":220,"props":3311,"children":3312},{"style":238},[3313],{"type":49,"value":470},{"type":43,"tag":220,"props":3315,"children":3316},{"style":238},[3317],{"type":49,"value":297},{"type":43,"tag":220,"props":3319,"children":3320},{"style":238},[3321],{"type":49,"value":459},{"type":43,"tag":220,"props":3323,"children":3324},{"style":462},[3325],{"type":49,"value":3326},"global-config",{"type":43,"tag":220,"props":3328,"children":3329},{"style":238},[3330],{"type":49,"value":470},{"type":43,"tag":220,"props":3332,"children":3333},{"style":238},[3334],{"type":49,"value":3335}," }\n",{"type":43,"tag":220,"props":3337,"children":3338},{"class":222,"line":601},[3339],{"type":43,"tag":220,"props":3340,"children":3341},{"emptyLinePlaceholder":259},[3342],{"type":49,"value":262},{"type":43,"tag":220,"props":3344,"children":3345},{"class":222,"line":610},[3346],{"type":43,"tag":220,"props":3347,"children":3348},{"style":622},[3349],{"type":49,"value":3350},"\u002F\u002F Naive tenant sharding: enterprise tenant overloads one shard\n",{"type":43,"tag":220,"props":3352,"children":3353},{"class":222,"line":618},[3354,3358,3363,3367,3371,3376,3380,3385],{"type":43,"tag":220,"props":3355,"children":3356},{"style":226},[3357],{"type":49,"value":229},{"type":43,"tag":220,"props":3359,"children":3360},{"style":232},[3361],{"type":49,"value":3362}," shard ",{"type":43,"tag":220,"props":3364,"children":3365},{"style":238},[3366],{"type":49,"value":241},{"type":43,"tag":220,"props":3368,"children":3369},{"style":278},[3370],{"type":49,"value":1678},{"type":43,"tag":220,"props":3372,"children":3373},{"style":232},[3374],{"type":49,"value":3375},"(tenantId) ",{"type":43,"tag":220,"props":3377,"children":3378},{"style":238},[3379],{"type":49,"value":1695},{"type":43,"tag":220,"props":3381,"children":3382},{"style":232},[3383],{"type":49,"value":3384}," NUM_SHARDS",{"type":43,"tag":220,"props":3386,"children":3387},{"style":238},[3388],{"type":49,"value":252},{"type":43,"tag":220,"props":3390,"children":3391},{"class":222,"line":628},[3392],{"type":43,"tag":220,"props":3393,"children":3394},{"emptyLinePlaceholder":259},[3395],{"type":49,"value":262},{"type":43,"tag":220,"props":3397,"children":3398},{"class":222,"line":695},[3399],{"type":43,"tag":220,"props":3400,"children":3401},{"style":622},[3402],{"type":49,"value":3403},"\u002F\u002F No per-partition monitoring: blind to imbalance\n",{"type":43,"tag":220,"props":3405,"children":3406},{"class":222,"line":735},[3407],{"type":43,"tag":220,"props":3408,"children":3409},{"style":622},[3410],{"type":49,"value":3411},"\u002F\u002F You find out when users report errors, not from metrics\n",{"type":43,"tag":64,"props":3413,"children":3415},{"id":3414},"related-traps",[3416],{"type":49,"value":3417},"Related Traps",{"type":43,"tag":3419,"props":3420,"children":3421},"ul",{},[3422,3432,3442],{"type":43,"tag":99,"props":3423,"children":3424},{},[3425,3430],{"type":43,"tag":58,"props":3426,"children":3427},{},[3428],{"type":49,"value":3429},"Cardinality",{"type":49,"value":3431}," -- low cardinality in partition keys directly causes hot partitions. If your key has 5 distinct values, you have at most 5 partitions, and the most popular value dominates.",{"type":43,"tag":99,"props":3433,"children":3434},{},[3435,3440],{"type":43,"tag":58,"props":3436,"children":3437},{},[3438],{"type":49,"value":3439},"Thundering Herd",{"type":49,"value":3441}," -- a thundering herd on a partitioned system concentrates the stampede on one partition. Cache expiry for a hot key creates both problems simultaneously.",{"type":43,"tag":99,"props":3443,"children":3444},{},[3445,3450],{"type":43,"tag":58,"props":3446,"children":3447},{},[3448],{"type":49,"value":3449},"Sharding",{"type":49,"value":3451}," -- hot partitions are the failure mode of bad shard key selection. The Sharding skill covers shard key choice; this skill covers what happens when the choice is wrong.",{"type":43,"tag":3453,"props":3454,"children":3455},"style",{},[3456],{"type":49,"value":3457},"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":3459,"total":834},[3460,3469,3481,3491,3503,3514,3526],{"slug":3461,"name":3461,"fn":3462,"description":3463,"org":3464,"tags":3465,"stars":26,"repoUrl":27,"updatedAt":3468},"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},[3466,3467],{"name":18,"slug":19,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:42.723559",{"slug":3470,"name":3470,"fn":3471,"description":3472,"org":3473,"tags":3474,"stars":26,"repoUrl":27,"updatedAt":3480},"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},[3475,3476,3478,3479],{"name":18,"slug":19,"type":16},{"name":3000,"slug":3477,"type":16},"caching",{"name":24,"slug":25,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:45.194583",{"slug":3482,"name":3482,"fn":3483,"description":3484,"org":3485,"tags":3486,"stars":26,"repoUrl":27,"updatedAt":3490},"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},[3487,3488,3489],{"name":18,"slug":19,"type":16},{"name":24,"slug":25,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:40.264608",{"slug":3492,"name":3492,"fn":3493,"description":3494,"org":3495,"tags":3496,"stars":26,"repoUrl":27,"updatedAt":3502},"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},[3497,3498,3501],{"name":18,"slug":19,"type":16},{"name":3499,"slug":3500,"type":16},"Debugging","debugging",{"name":24,"slug":25,"type":16},"2026-06-17T08:40:37.803541",{"slug":3504,"name":3504,"fn":3505,"description":3506,"org":3507,"tags":3508,"stars":26,"repoUrl":27,"updatedAt":3513},"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},[3509,3510,3511,3512],{"name":18,"slug":19,"type":16},{"name":21,"slug":22,"type":16},{"name":24,"slug":25,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:46.442182",{"slug":3515,"name":3515,"fn":3516,"description":3517,"org":3518,"tags":3519,"stars":26,"repoUrl":27,"updatedAt":3525},"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},[3520,3521,3524],{"name":18,"slug":19,"type":16},{"name":3522,"slug":3523,"type":16},"Data Modeling","data-modeling",{"name":21,"slug":22,"type":16},"2026-06-17T08:40:53.835868",{"slug":3527,"name":3527,"fn":3528,"description":3529,"org":3530,"tags":3531,"stars":26,"repoUrl":27,"updatedAt":3537},"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},[3532,3535,3536],{"name":3533,"slug":3534,"type":16},"API Development","api-development",{"name":18,"slug":19,"type":16},{"name":24,"slug":25,"type":16},"2026-06-17T08:40:47.666795",{"items":3539,"total":3693},[3540,3559,3572,3582,3599,3614,3628,3645,3658,3670,3681,3686],{"slug":3541,"name":3541,"fn":3542,"description":3543,"org":3544,"tags":3545,"stars":3556,"repoUrl":3557,"updatedAt":3558},"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},[3546,3549,3552,3553],{"name":3547,"slug":3548,"type":16},"Agents","agents",{"name":3550,"slug":3551,"type":16},"SDK","sdk",{"name":9,"slug":8,"type":16},{"name":3554,"slug":3555,"type":16},"Workflow Automation","workflow-automation",14401,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Ftrigger.dev","2026-07-02T17:12:52.307135",{"slug":3560,"name":3560,"fn":3561,"description":3562,"org":3563,"tags":3564,"stars":3556,"repoUrl":3557,"updatedAt":3571},"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},[3565,3568,3569,3570],{"name":3566,"slug":3567,"type":16},"Backend","backend",{"name":3550,"slug":3551,"type":16},{"name":9,"slug":8,"type":16},{"name":3554,"slug":3555,"type":16},"2026-07-02T17:12:48.396964",{"slug":3573,"name":3573,"fn":3574,"description":3575,"org":3576,"tags":3577,"stars":3556,"repoUrl":3557,"updatedAt":3581},"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},[3578,3579,3580],{"name":3547,"slug":3548,"type":16},{"name":9,"slug":8,"type":16},{"name":3554,"slug":3555,"type":16},"2026-07-02T17:12:51.03018",{"slug":3583,"name":3583,"fn":3584,"description":3585,"org":3586,"tags":3587,"stars":3556,"repoUrl":3557,"updatedAt":3598},"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},[3588,3591,3594,3597],{"name":3589,"slug":3590,"type":16},"Frontend","frontend",{"name":3592,"slug":3593,"type":16},"React","react",{"name":3595,"slug":3596,"type":16},"Real-time","real-time",{"name":9,"slug":8,"type":16},"2026-07-02T17:12:49.717706",{"slug":3600,"name":3600,"fn":3601,"description":3602,"org":3603,"tags":3604,"stars":3611,"repoUrl":3612,"updatedAt":3613},"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},[3605,3606,3609,3610],{"name":3547,"slug":3548,"type":16},{"name":3607,"slug":3608,"type":16},"Multi-Agent","multi-agent",{"name":9,"slug":8,"type":16},{"name":3554,"slug":3555,"type":16},30,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fskills","2026-04-06T18:54:46.023553",{"slug":3615,"name":3615,"fn":3616,"description":3617,"org":3618,"tags":3619,"stars":3611,"repoUrl":3612,"updatedAt":3627},"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},[3620,3623,3626],{"name":3621,"slug":3622,"type":16},"Configuration","configuration",{"name":3624,"slug":3625,"type":16},"Deployment","deployment",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:44.764258",{"slug":3629,"name":3629,"fn":3630,"description":3631,"org":3632,"tags":3633,"stars":3611,"repoUrl":3612,"updatedAt":3644},"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},[3634,3637,3640,3643],{"name":3635,"slug":3636,"type":16},"Analytics","analytics",{"name":3638,"slug":3639,"type":16},"Cost Optimization","cost-optimization",{"name":3641,"slug":3642,"type":16},"Operations","operations",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:48.555552",{"slug":3646,"name":3646,"fn":3647,"description":3648,"org":3649,"tags":3650,"stars":3611,"repoUrl":3612,"updatedAt":3657},"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},[3651,3652,3655,3656],{"name":3589,"slug":3590,"type":16},{"name":3653,"slug":3654,"type":16},"Observability","observability",{"name":3595,"slug":3596,"type":16},{"name":9,"slug":8,"type":16},"2026-04-06T18:54:47.293822",{"slug":3659,"name":3659,"fn":3660,"description":3661,"org":3662,"tags":3663,"stars":3611,"repoUrl":3612,"updatedAt":3669},"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},[3664,3665,3668],{"name":3621,"slug":3622,"type":16},{"name":3666,"slug":3667,"type":16},"Local Development","local-development",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:42.280816",{"slug":3671,"name":3671,"fn":3672,"description":3673,"org":3674,"tags":3675,"stars":3611,"repoUrl":3612,"updatedAt":3680},"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},[3676,3677,3678,3679],{"name":3547,"slug":3548,"type":16},{"name":3566,"slug":3567,"type":16},{"name":9,"slug":8,"type":16},{"name":3554,"slug":3555,"type":16},"2026-04-06T18:54:43.514369",{"slug":3461,"name":3461,"fn":3462,"description":3463,"org":3682,"tags":3683,"stars":26,"repoUrl":27,"updatedAt":3468},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3684,3685],{"name":18,"slug":19,"type":16},{"name":14,"slug":15,"type":16},{"slug":3470,"name":3470,"fn":3471,"description":3472,"org":3687,"tags":3688,"stars":26,"repoUrl":27,"updatedAt":3480},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3689,3690,3691,3692],{"name":18,"slug":19,"type":16},{"name":3000,"slug":3477,"type":16},{"name":24,"slug":25,"type":16},{"name":14,"slug":15,"type":16},26]