[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-trigger-dev-staff-engineering-skills-cardinality":3,"mdc--978ifd-key":34,"related-org-trigger-dev-staff-engineering-skills-cardinality":2742,"related-repo-trigger-dev-staff-engineering-skills-cardinality":2908},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":12,"stars":23,"repoUrl":24,"updatedAt":25,"license":26,"forks":27,"topics":28,"repo":29,"sourceUrl":32,"mdContent":33},"staff-engineering-skills-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},"trigger-dev","Trigger.dev","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Ftrigger-dev.jpg","triggerdotdev",[13,17,20],{"name":14,"slug":15,"type":16},"Performance","performance","tag",{"name":18,"slug":19,"type":16},"Architecture","architecture",{"name":21,"slug":22,"type":16},"Engineering","engineering",3,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills","2026-06-17T08:40:40.264608",null,1,[],{"repoUrl":24,"stars":23,"forks":27,"topics":30,"description":31},[],"Skills that give AI   coding agents staff-engineer instincts: recognizing and avoiding production failure modes like cardinality, idempotency, and race conditions.","https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fstaff-engineering-skills\u002Ftree\u002FHEAD\u002Fskills\u002Fstaff-engineering-skills-cardinality","---\nname: staff-engineering-skills-cardinality\ndescription: 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.\n---\n\n# Cardinality Trap\n\nCode that works for 10 items becomes a production incident at 10 million. Before writing any code that operates on a collection, ask: **how many items can this collection contain, and what controls that number?**\n\n## The Cardinality Levels\n\nClassify every collection you touch:\n\n| Level | Controlled by | Examples | Safe to load in memory? |\n|-------|--------------|----------|------------------------|\n| **L1** | Code (deploy to change) | Enums, feature flags, status codes | Yes |\n| **L2** | Real-world constraints | Countries, US states, time zones | Yes, but verify count |\n| **L3** | User action + limits | Team members (capped at 50), projects per workspace | With caution. Limits change. |\n| **L4** | User action, no limits | Documents, messages, spreadsheet rows | No. Paginate always. |\n| **L5** | API\u002Fautomation + time | API requests, log entries, webhook events, metrics | No. Assume millions. Stream or batch. |\n\n**The 2nd Degree Rule:** Treat L4 as L5. User-driven collections almost always gain API access later. \"Documents in a drive\" becomes \"documents created by an integration every 5 minutes.\"\n\n## Detection: When You're About to Write Cardinality-Sensitive Code\n\n**Stop and assess cardinality if you're about to write any of these:**\n\n1. **`for (const x of collection)` \u002F `.map()` \u002F `.forEach()`** on a query result -- what bounds `collection`? If it's user-controlled or time-accumulating, it's L4\u002FL5.\n\n2. **`new Map()` or `new Set()` populated from a database** -- what bounds its size? If the answer is \"number of users\u002Fdocuments\u002Fevents,\" it will grow without limit.\n\n3. **\"One X per Y\"** -- one queue per customer, one timer per session, one connection per tenant. What's the cardinality of Y?\n\n4. **`SELECT * FROM table` without LIMIT** -- what's the row count trajectory? Tables that accumulate over time are unbounded.\n\n5. **`Promise.all(items.map(...))` for fan-out** -- what's the max length of `items`? Unbounded fan-out exhausts connection pools and memory.\n\n6. **Per-entity time series** -- metrics per org, events per user. The cross product (entities x time intervals) is multiplicative cardinality.\n\n## Decision Checklist\n\nBefore writing code that touches a collection, answer these:\n\n- [ ] What is the cardinality level (L1-L5)?\n- [ ] What is the current count? What will it be in 1 year?\n- [ ] Is the entire collection loaded into memory at any point?\n- [ ] Is there a resource created per item (timer, connection, goroutine, queue)?\n- [ ] What happens if the collection is 1000x larger than today?\n- [ ] Could this collection ever be populated by an API? (If yes, treat as L5)\n\n## Patterns\n\n### L1-L2: Direct iteration is fine\n\n```typescript\n\u002F\u002F Safe: status is an enum (L1), countries are bounded (L2)\nconst results = statusValues.map(s => getCountByStatus(s));\n```\n\n### L3+: Paginate and bound\n\n```typescript\n\u002F\u002F Dangerous\nconst orgs = await db.organization.findMany({ where: { status: \"active\" } });\norgs.forEach(org => process(org));\n\n\u002F\u002F Safe: cursor-based pagination with bounded batches\nlet cursor: string | undefined;\ndo {\n  const batch = await db.organization.findMany({\n    where: { status: \"active\" },\n    take: 100,\n    cursor: cursor ? { id: cursor } : undefined,\n    orderBy: { id: \"asc\" },\n  });\n  for (const org of batch) await process(org);\n  cursor = batch.length === 100 ? batch[batch.length - 1].id : undefined;\n} while (cursor);\n```\n\n### Aggregate in the database, not in memory\n\n```typescript\n\u002F\u002F Dangerous: loads all events into memory to count them\nconst events = await getAllEvents(orgId);\nconst counts = new Map\u003Cstring, number>();\nfor (const e of events) counts.set(e.type, (counts.get(e.type) || 0) + 1);\n\n\u002F\u002F Safe: push aggregation to the database\nconst counts = await db.$queryRaw`\n  SELECT event_type, COUNT(*) as count\n  FROM events WHERE org_id = ${orgId}\n  GROUP BY event_type\n`;\n```\n\n### Bound fan-out with queuing\n\n```typescript\n\u002F\u002F Dangerous: unbounded concurrent fan-out\nconst members = await getTeamMembers(teamId);\nawait Promise.all(members.map(m => sendNotification(m.id, message)));\n\n\u002F\u002F Safe: check cardinality, branch strategy\nconst count = await getTeamMemberCount(teamId);\nif (count > DIRECT_THRESHOLD) {\n  await enqueueJob(\"notify-team\", { teamId, message }); \u002F\u002F batched in background\n} else {\n  const members = await getTeamMembers(teamId);\n  await Promise.all(members.map(m => sendNotification(m.id, message)));\n}\n```\n\n### Never create unbounded per-entity resources\n\n```typescript\n\u002F\u002F Dangerous: one timer per session, never cleaned up\nfor (const session of sessions) {\n  setInterval(() => pingSession(session.id), 30_000);\n}\n\n\u002F\u002F Safe: single timer that iterates, or use a bounded pool\nconst sessionPinger = setInterval(async () => {\n  const activeSessions = await getActiveSessions({ limit: 1000 });\n  for (const session of activeSessions) await pingSession(session.id);\n}, 30_000);\n```\n\n### Metrics and time series: multiplicative cardinality\n\nMetric labels and time series are the most common hidden cardinality trap. The total series count is the cross product of every label value combination, and it grows multiplicatively.\n\n```typescript\n\u002F\u002F Dangerous: per-tenant metric label. 50,000 tenants x 20 metrics = 1M series.\n\u002F\u002F Prometheus\u002FVictoria\u002FDatadog all choke on high-cardinality labels.\nmetrics.increment(\"api.requests\", { tenant: tenantId, endpoint, method, status });\n\u002F\u002F If tenantId has 50K values, endpoint has 200, method has 5, status has 5:\n\u002F\u002F 50,000 x 200 x 5 x 5 = 250,000,000 unique series. Your monitoring is dead.\n\n\u002F\u002F Safe: use bounded labels only. Aggregate per-tenant metrics separately.\nmetrics.increment(\"api.requests\", { endpoint, method, status }); \u002F\u002F L1 labels only\n\u002F\u002F Per-tenant data goes to a dedicated analytics pipeline (ClickHouse, BigQuery)\n\u002F\u002F that's designed for high-cardinality dimensional queries.\n```\n\n**The rule:** Every metric label must be L1 or L2. If you need per-tenant, per-user, or per-entity metrics, that's an analytics query, not a metric. Route it to a system designed for high-cardinality queries (ClickHouse, BigQuery, Tinybird) rather than a monitoring system (Prometheus, Datadog, Grafana Cloud) that charges per series or collapses under high cardinality.\n\n## Anti-Patterns\n\n- **Loading an unbounded collection into memory** -- `findMany()` with no `take`, then filtering or mapping in app code. Filter and bound in the query; paginate L4\u002FL5 sets.\n- **One resource per entity** -- a `setInterval`, connection, queue, or goroutine created per item in a loop. Use a single iterating worker or a bounded pool.\n- **Aggregating in memory** -- pulling every row to count\u002Fsum\u002Fgroup in app code. Push the aggregation into the database (`GROUP BY`).\n- **Unbounded fan-out** -- `Promise.all(items.map(...))` over a user- or API-sized array. Check the count and branch to a queue past a threshold.\n- **High-cardinality metric labels** -- per-tenant\u002Fuser\u002Fentity labels on a monitoring metric. Keep labels L1\u002FL2; route per-entity analytics to a columnar store.\n\n## Related Traps\n\n- **Denormalization** -- denormalizing into a high-cardinality set creates write amplification proportional to the set size.\n- **Backpressure** -- unbounded fan-out without backpressure collapses under high cardinality.\n- **Memory Leaks** -- unbounded `Map`\u002F`Set` at module scope is both a cardinality trap and a memory leak.\n- **Streams vs Batch** -- high cardinality is the forcing function that moves you from batch to streaming.\n",{"data":35,"body":36},{"name":4,"description":6},{"type":37,"children":38},"root",[39,48,60,67,72,240,250,256,264,391,397,402,466,472,479,570,576,1227,1233,1561,1567,1987,1993,2312,2318,2323,2564,2574,2580,2671,2677,2736],{"type":40,"tag":41,"props":42,"children":44},"element","h1",{"id":43},"cardinality-trap",[45],{"type":46,"value":47},"text","Cardinality Trap",{"type":40,"tag":49,"props":50,"children":51},"p",{},[52,54],{"type":46,"value":53},"Code that works for 10 items becomes a production incident at 10 million. Before writing any code that operates on a collection, ask: ",{"type":40,"tag":55,"props":56,"children":57},"strong",{},[58],{"type":46,"value":59},"how many items can this collection contain, and what controls that number?",{"type":40,"tag":61,"props":62,"children":64},"h2",{"id":63},"the-cardinality-levels",[65],{"type":46,"value":66},"The Cardinality Levels",{"type":40,"tag":49,"props":68,"children":69},{},[70],{"type":46,"value":71},"Classify every collection you touch:",{"type":40,"tag":73,"props":74,"children":75},"table",{},[76,105],{"type":40,"tag":77,"props":78,"children":79},"thead",{},[80],{"type":40,"tag":81,"props":82,"children":83},"tr",{},[84,90,95,100],{"type":40,"tag":85,"props":86,"children":87},"th",{},[88],{"type":46,"value":89},"Level",{"type":40,"tag":85,"props":91,"children":92},{},[93],{"type":46,"value":94},"Controlled by",{"type":40,"tag":85,"props":96,"children":97},{},[98],{"type":46,"value":99},"Examples",{"type":40,"tag":85,"props":101,"children":102},{},[103],{"type":46,"value":104},"Safe to load in memory?",{"type":40,"tag":106,"props":107,"children":108},"tbody",{},[109,136,162,188,214],{"type":40,"tag":81,"props":110,"children":111},{},[112,121,126,131],{"type":40,"tag":113,"props":114,"children":115},"td",{},[116],{"type":40,"tag":55,"props":117,"children":118},{},[119],{"type":46,"value":120},"L1",{"type":40,"tag":113,"props":122,"children":123},{},[124],{"type":46,"value":125},"Code (deploy to change)",{"type":40,"tag":113,"props":127,"children":128},{},[129],{"type":46,"value":130},"Enums, feature flags, status codes",{"type":40,"tag":113,"props":132,"children":133},{},[134],{"type":46,"value":135},"Yes",{"type":40,"tag":81,"props":137,"children":138},{},[139,147,152,157],{"type":40,"tag":113,"props":140,"children":141},{},[142],{"type":40,"tag":55,"props":143,"children":144},{},[145],{"type":46,"value":146},"L2",{"type":40,"tag":113,"props":148,"children":149},{},[150],{"type":46,"value":151},"Real-world constraints",{"type":40,"tag":113,"props":153,"children":154},{},[155],{"type":46,"value":156},"Countries, US states, time zones",{"type":40,"tag":113,"props":158,"children":159},{},[160],{"type":46,"value":161},"Yes, but verify count",{"type":40,"tag":81,"props":163,"children":164},{},[165,173,178,183],{"type":40,"tag":113,"props":166,"children":167},{},[168],{"type":40,"tag":55,"props":169,"children":170},{},[171],{"type":46,"value":172},"L3",{"type":40,"tag":113,"props":174,"children":175},{},[176],{"type":46,"value":177},"User action + limits",{"type":40,"tag":113,"props":179,"children":180},{},[181],{"type":46,"value":182},"Team members (capped at 50), projects per workspace",{"type":40,"tag":113,"props":184,"children":185},{},[186],{"type":46,"value":187},"With caution. Limits change.",{"type":40,"tag":81,"props":189,"children":190},{},[191,199,204,209],{"type":40,"tag":113,"props":192,"children":193},{},[194],{"type":40,"tag":55,"props":195,"children":196},{},[197],{"type":46,"value":198},"L4",{"type":40,"tag":113,"props":200,"children":201},{},[202],{"type":46,"value":203},"User action, no limits",{"type":40,"tag":113,"props":205,"children":206},{},[207],{"type":46,"value":208},"Documents, messages, spreadsheet rows",{"type":40,"tag":113,"props":210,"children":211},{},[212],{"type":46,"value":213},"No. Paginate always.",{"type":40,"tag":81,"props":215,"children":216},{},[217,225,230,235],{"type":40,"tag":113,"props":218,"children":219},{},[220],{"type":40,"tag":55,"props":221,"children":222},{},[223],{"type":46,"value":224},"L5",{"type":40,"tag":113,"props":226,"children":227},{},[228],{"type":46,"value":229},"API\u002Fautomation + time",{"type":40,"tag":113,"props":231,"children":232},{},[233],{"type":46,"value":234},"API requests, log entries, webhook events, metrics",{"type":40,"tag":113,"props":236,"children":237},{},[238],{"type":46,"value":239},"No. Assume millions. Stream or batch.",{"type":40,"tag":49,"props":241,"children":242},{},[243,248],{"type":40,"tag":55,"props":244,"children":245},{},[246],{"type":46,"value":247},"The 2nd Degree Rule:",{"type":46,"value":249}," Treat L4 as L5. User-driven collections almost always gain API access later. \"Documents in a drive\" becomes \"documents created by an integration every 5 minutes.\"",{"type":40,"tag":61,"props":251,"children":253},{"id":252},"detection-when-youre-about-to-write-cardinality-sensitive-code",[254],{"type":46,"value":255},"Detection: When You're About to Write Cardinality-Sensitive Code",{"type":40,"tag":49,"props":257,"children":258},{},[259],{"type":40,"tag":55,"props":260,"children":261},{},[262],{"type":46,"value":263},"Stop and assess cardinality if you're about to write any of these:",{"type":40,"tag":265,"props":266,"children":267},"ol",{},[268,307,331,341,357,381],{"type":40,"tag":269,"props":270,"children":271},"li",{},[272,297,299,305],{"type":40,"tag":55,"props":273,"children":274},{},[275,282,284,290,291],{"type":40,"tag":276,"props":277,"children":279},"code",{"className":278},[],[280],{"type":46,"value":281},"for (const x of collection)",{"type":46,"value":283}," \u002F ",{"type":40,"tag":276,"props":285,"children":287},{"className":286},[],[288],{"type":46,"value":289},".map()",{"type":46,"value":283},{"type":40,"tag":276,"props":292,"children":294},{"className":293},[],[295],{"type":46,"value":296},".forEach()",{"type":46,"value":298}," on a query result -- what bounds ",{"type":40,"tag":276,"props":300,"children":302},{"className":301},[],[303],{"type":46,"value":304},"collection",{"type":46,"value":306},"? If it's user-controlled or time-accumulating, it's L4\u002FL5.",{"type":40,"tag":269,"props":308,"children":309},{},[310,329],{"type":40,"tag":55,"props":311,"children":312},{},[313,319,321,327],{"type":40,"tag":276,"props":314,"children":316},{"className":315},[],[317],{"type":46,"value":318},"new Map()",{"type":46,"value":320}," or ",{"type":40,"tag":276,"props":322,"children":324},{"className":323},[],[325],{"type":46,"value":326},"new Set()",{"type":46,"value":328}," populated from a database",{"type":46,"value":330}," -- what bounds its size? If the answer is \"number of users\u002Fdocuments\u002Fevents,\" it will grow without limit.",{"type":40,"tag":269,"props":332,"children":333},{},[334,339],{"type":40,"tag":55,"props":335,"children":336},{},[337],{"type":46,"value":338},"\"One X per Y\"",{"type":46,"value":340}," -- one queue per customer, one timer per session, one connection per tenant. What's the cardinality of Y?",{"type":40,"tag":269,"props":342,"children":343},{},[344,355],{"type":40,"tag":55,"props":345,"children":346},{},[347,353],{"type":40,"tag":276,"props":348,"children":350},{"className":349},[],[351],{"type":46,"value":352},"SELECT * FROM table",{"type":46,"value":354}," without LIMIT",{"type":46,"value":356}," -- what's the row count trajectory? Tables that accumulate over time are unbounded.",{"type":40,"tag":269,"props":358,"children":359},{},[360,371,373,379],{"type":40,"tag":55,"props":361,"children":362},{},[363,369],{"type":40,"tag":276,"props":364,"children":366},{"className":365},[],[367],{"type":46,"value":368},"Promise.all(items.map(...))",{"type":46,"value":370}," for fan-out",{"type":46,"value":372}," -- what's the max length of ",{"type":40,"tag":276,"props":374,"children":376},{"className":375},[],[377],{"type":46,"value":378},"items",{"type":46,"value":380},"? Unbounded fan-out exhausts connection pools and memory.",{"type":40,"tag":269,"props":382,"children":383},{},[384,389],{"type":40,"tag":55,"props":385,"children":386},{},[387],{"type":46,"value":388},"Per-entity time series",{"type":46,"value":390}," -- metrics per org, events per user. The cross product (entities x time intervals) is multiplicative cardinality.",{"type":40,"tag":61,"props":392,"children":394},{"id":393},"decision-checklist",[395],{"type":46,"value":396},"Decision Checklist",{"type":40,"tag":49,"props":398,"children":399},{},[400],{"type":46,"value":401},"Before writing code that touches a collection, answer these:",{"type":40,"tag":403,"props":404,"children":407},"ul",{"className":405},[406],"contains-task-list",[408,421,430,439,448,457],{"type":40,"tag":269,"props":409,"children":412},{"className":410},[411],"task-list-item",[413,419],{"type":40,"tag":414,"props":415,"children":418},"input",{"disabled":416,"type":417},true,"checkbox",[],{"type":46,"value":420}," What is the cardinality level (L1-L5)?",{"type":40,"tag":269,"props":422,"children":424},{"className":423},[411],[425,428],{"type":40,"tag":414,"props":426,"children":427},{"disabled":416,"type":417},[],{"type":46,"value":429}," What is the current count? What will it be in 1 year?",{"type":40,"tag":269,"props":431,"children":433},{"className":432},[411],[434,437],{"type":40,"tag":414,"props":435,"children":436},{"disabled":416,"type":417},[],{"type":46,"value":438}," Is the entire collection loaded into memory at any point?",{"type":40,"tag":269,"props":440,"children":442},{"className":441},[411],[443,446],{"type":40,"tag":414,"props":444,"children":445},{"disabled":416,"type":417},[],{"type":46,"value":447}," Is there a resource created per item (timer, connection, goroutine, queue)?",{"type":40,"tag":269,"props":449,"children":451},{"className":450},[411],[452,455],{"type":40,"tag":414,"props":453,"children":454},{"disabled":416,"type":417},[],{"type":46,"value":456}," What happens if the collection is 1000x larger than today?",{"type":40,"tag":269,"props":458,"children":460},{"className":459},[411],[461,464],{"type":40,"tag":414,"props":462,"children":463},{"disabled":416,"type":417},[],{"type":46,"value":465}," Could this collection ever be populated by an API? (If yes, treat as L5)",{"type":40,"tag":61,"props":467,"children":469},{"id":468},"patterns",[470],{"type":46,"value":471},"Patterns",{"type":40,"tag":473,"props":474,"children":476},"h3",{"id":475},"l1-l2-direct-iteration-is-fine",[477],{"type":46,"value":478},"L1-L2: Direct iteration is fine",{"type":40,"tag":480,"props":481,"children":486},"pre",{"className":482,"code":483,"language":484,"meta":485,"style":485},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Safe: status is an enum (L1), countries are bounded (L2)\nconst results = statusValues.map(s => getCountByStatus(s));\n","typescript","",[487],{"type":40,"tag":276,"props":488,"children":489},{"__ignoreMap":485},[490,501],{"type":40,"tag":491,"props":492,"children":494},"span",{"class":493,"line":27},"line",[495],{"type":40,"tag":491,"props":496,"children":498},{"style":497},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[499],{"type":46,"value":500},"\u002F\u002F Safe: status is an enum (L1), countries are bounded (L2)\n",{"type":40,"tag":491,"props":502,"children":504},{"class":493,"line":503},2,[505,511,517,523,528,533,539,544,550,555,560,565],{"type":40,"tag":491,"props":506,"children":508},{"style":507},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[509],{"type":46,"value":510},"const",{"type":40,"tag":491,"props":512,"children":514},{"style":513},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[515],{"type":46,"value":516}," results ",{"type":40,"tag":491,"props":518,"children":520},{"style":519},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[521],{"type":46,"value":522},"=",{"type":40,"tag":491,"props":524,"children":525},{"style":513},[526],{"type":46,"value":527}," statusValues",{"type":40,"tag":491,"props":529,"children":530},{"style":519},[531],{"type":46,"value":532},".",{"type":40,"tag":491,"props":534,"children":536},{"style":535},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[537],{"type":46,"value":538},"map",{"type":40,"tag":491,"props":540,"children":541},{"style":513},[542],{"type":46,"value":543},"(",{"type":40,"tag":491,"props":545,"children":547},{"style":546},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic",[548],{"type":46,"value":549},"s",{"type":40,"tag":491,"props":551,"children":552},{"style":507},[553],{"type":46,"value":554}," =>",{"type":40,"tag":491,"props":556,"children":557},{"style":535},[558],{"type":46,"value":559}," getCountByStatus",{"type":40,"tag":491,"props":561,"children":562},{"style":513},[563],{"type":46,"value":564},"(s))",{"type":40,"tag":491,"props":566,"children":567},{"style":519},[568],{"type":46,"value":569},";\n",{"type":40,"tag":473,"props":571,"children":573},{"id":572},"l3-paginate-and-bound",[574],{"type":46,"value":575},"L3+: Paginate and bound",{"type":40,"tag":480,"props":577,"children":579},{"className":482,"code":578,"language":484,"meta":485,"style":485},"\u002F\u002F Dangerous\nconst orgs = await db.organization.findMany({ where: { status: \"active\" } });\norgs.forEach(org => process(org));\n\n\u002F\u002F Safe: cursor-based pagination with bounded batches\nlet cursor: string | undefined;\ndo {\n  const batch = await db.organization.findMany({\n    where: { status: \"active\" },\n    take: 100,\n    cursor: cursor ? { id: cursor } : undefined,\n    orderBy: { id: \"asc\" },\n  });\n  for (const org of batch) await process(org);\n  cursor = batch.length === 100 ? batch[batch.length - 1].id : undefined;\n} while (cursor);\n",[580],{"type":40,"tag":276,"props":581,"children":582},{"__ignoreMap":485},[583,591,704,748,757,766,804,818,870,912,936,989,1031,1048,1110,1204],{"type":40,"tag":491,"props":584,"children":585},{"class":493,"line":27},[586],{"type":40,"tag":491,"props":587,"children":588},{"style":497},[589],{"type":46,"value":590},"\u002F\u002F Dangerous\n",{"type":40,"tag":491,"props":592,"children":593},{"class":493,"line":503},[594,598,603,607,613,618,622,627,631,636,640,645,651,656,661,666,670,675,681,686,691,695,700],{"type":40,"tag":491,"props":595,"children":596},{"style":507},[597],{"type":46,"value":510},{"type":40,"tag":491,"props":599,"children":600},{"style":513},[601],{"type":46,"value":602}," orgs ",{"type":40,"tag":491,"props":604,"children":605},{"style":519},[606],{"type":46,"value":522},{"type":40,"tag":491,"props":608,"children":610},{"style":609},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[611],{"type":46,"value":612}," await",{"type":40,"tag":491,"props":614,"children":615},{"style":513},[616],{"type":46,"value":617}," db",{"type":40,"tag":491,"props":619,"children":620},{"style":519},[621],{"type":46,"value":532},{"type":40,"tag":491,"props":623,"children":624},{"style":513},[625],{"type":46,"value":626},"organization",{"type":40,"tag":491,"props":628,"children":629},{"style":519},[630],{"type":46,"value":532},{"type":40,"tag":491,"props":632,"children":633},{"style":535},[634],{"type":46,"value":635},"findMany",{"type":40,"tag":491,"props":637,"children":638},{"style":513},[639],{"type":46,"value":543},{"type":40,"tag":491,"props":641,"children":642},{"style":519},[643],{"type":46,"value":644},"{",{"type":40,"tag":491,"props":646,"children":648},{"style":647},"--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178",[649],{"type":46,"value":650}," where",{"type":40,"tag":491,"props":652,"children":653},{"style":519},[654],{"type":46,"value":655},":",{"type":40,"tag":491,"props":657,"children":658},{"style":519},[659],{"type":46,"value":660}," {",{"type":40,"tag":491,"props":662,"children":663},{"style":647},[664],{"type":46,"value":665}," status",{"type":40,"tag":491,"props":667,"children":668},{"style":519},[669],{"type":46,"value":655},{"type":40,"tag":491,"props":671,"children":672},{"style":519},[673],{"type":46,"value":674}," \"",{"type":40,"tag":491,"props":676,"children":678},{"style":677},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[679],{"type":46,"value":680},"active",{"type":40,"tag":491,"props":682,"children":683},{"style":519},[684],{"type":46,"value":685},"\"",{"type":40,"tag":491,"props":687,"children":688},{"style":519},[689],{"type":46,"value":690}," }",{"type":40,"tag":491,"props":692,"children":693},{"style":519},[694],{"type":46,"value":690},{"type":40,"tag":491,"props":696,"children":697},{"style":513},[698],{"type":46,"value":699},")",{"type":40,"tag":491,"props":701,"children":702},{"style":519},[703],{"type":46,"value":569},{"type":40,"tag":491,"props":705,"children":706},{"class":493,"line":23},[707,712,716,721,725,730,734,739,744],{"type":40,"tag":491,"props":708,"children":709},{"style":513},[710],{"type":46,"value":711},"orgs",{"type":40,"tag":491,"props":713,"children":714},{"style":519},[715],{"type":46,"value":532},{"type":40,"tag":491,"props":717,"children":718},{"style":535},[719],{"type":46,"value":720},"forEach",{"type":40,"tag":491,"props":722,"children":723},{"style":513},[724],{"type":46,"value":543},{"type":40,"tag":491,"props":726,"children":727},{"style":546},[728],{"type":46,"value":729},"org",{"type":40,"tag":491,"props":731,"children":732},{"style":507},[733],{"type":46,"value":554},{"type":40,"tag":491,"props":735,"children":736},{"style":535},[737],{"type":46,"value":738}," process",{"type":40,"tag":491,"props":740,"children":741},{"style":513},[742],{"type":46,"value":743},"(org))",{"type":40,"tag":491,"props":745,"children":746},{"style":519},[747],{"type":46,"value":569},{"type":40,"tag":491,"props":749,"children":751},{"class":493,"line":750},4,[752],{"type":40,"tag":491,"props":753,"children":754},{"emptyLinePlaceholder":416},[755],{"type":46,"value":756},"\n",{"type":40,"tag":491,"props":758,"children":760},{"class":493,"line":759},5,[761],{"type":40,"tag":491,"props":762,"children":763},{"style":497},[764],{"type":46,"value":765},"\u002F\u002F Safe: cursor-based pagination with bounded batches\n",{"type":40,"tag":491,"props":767,"children":769},{"class":493,"line":768},6,[770,775,780,784,790,795,800],{"type":40,"tag":491,"props":771,"children":772},{"style":507},[773],{"type":46,"value":774},"let",{"type":40,"tag":491,"props":776,"children":777},{"style":513},[778],{"type":46,"value":779}," cursor",{"type":40,"tag":491,"props":781,"children":782},{"style":519},[783],{"type":46,"value":655},{"type":40,"tag":491,"props":785,"children":787},{"style":786},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[788],{"type":46,"value":789}," string",{"type":40,"tag":491,"props":791,"children":792},{"style":519},[793],{"type":46,"value":794}," |",{"type":40,"tag":491,"props":796,"children":797},{"style":786},[798],{"type":46,"value":799}," undefined",{"type":40,"tag":491,"props":801,"children":802},{"style":519},[803],{"type":46,"value":569},{"type":40,"tag":491,"props":805,"children":807},{"class":493,"line":806},7,[808,813],{"type":40,"tag":491,"props":809,"children":810},{"style":609},[811],{"type":46,"value":812},"do",{"type":40,"tag":491,"props":814,"children":815},{"style":519},[816],{"type":46,"value":817}," {\n",{"type":40,"tag":491,"props":819,"children":821},{"class":493,"line":820},8,[822,827,832,837,841,845,849,853,857,861,865],{"type":40,"tag":491,"props":823,"children":824},{"style":507},[825],{"type":46,"value":826},"  const",{"type":40,"tag":491,"props":828,"children":829},{"style":513},[830],{"type":46,"value":831}," batch",{"type":40,"tag":491,"props":833,"children":834},{"style":519},[835],{"type":46,"value":836}," =",{"type":40,"tag":491,"props":838,"children":839},{"style":609},[840],{"type":46,"value":612},{"type":40,"tag":491,"props":842,"children":843},{"style":513},[844],{"type":46,"value":617},{"type":40,"tag":491,"props":846,"children":847},{"style":519},[848],{"type":46,"value":532},{"type":40,"tag":491,"props":850,"children":851},{"style":513},[852],{"type":46,"value":626},{"type":40,"tag":491,"props":854,"children":855},{"style":519},[856],{"type":46,"value":532},{"type":40,"tag":491,"props":858,"children":859},{"style":535},[860],{"type":46,"value":635},{"type":40,"tag":491,"props":862,"children":863},{"style":647},[864],{"type":46,"value":543},{"type":40,"tag":491,"props":866,"children":867},{"style":519},[868],{"type":46,"value":869},"{\n",{"type":40,"tag":491,"props":871,"children":873},{"class":493,"line":872},9,[874,879,883,887,891,895,899,903,907],{"type":40,"tag":491,"props":875,"children":876},{"style":647},[877],{"type":46,"value":878},"    where",{"type":40,"tag":491,"props":880,"children":881},{"style":519},[882],{"type":46,"value":655},{"type":40,"tag":491,"props":884,"children":885},{"style":519},[886],{"type":46,"value":660},{"type":40,"tag":491,"props":888,"children":889},{"style":647},[890],{"type":46,"value":665},{"type":40,"tag":491,"props":892,"children":893},{"style":519},[894],{"type":46,"value":655},{"type":40,"tag":491,"props":896,"children":897},{"style":519},[898],{"type":46,"value":674},{"type":40,"tag":491,"props":900,"children":901},{"style":677},[902],{"type":46,"value":680},{"type":40,"tag":491,"props":904,"children":905},{"style":519},[906],{"type":46,"value":685},{"type":40,"tag":491,"props":908,"children":909},{"style":519},[910],{"type":46,"value":911}," },\n",{"type":40,"tag":491,"props":913,"children":915},{"class":493,"line":914},10,[916,921,925,931],{"type":40,"tag":491,"props":917,"children":918},{"style":647},[919],{"type":46,"value":920},"    take",{"type":40,"tag":491,"props":922,"children":923},{"style":519},[924],{"type":46,"value":655},{"type":40,"tag":491,"props":926,"children":928},{"style":927},"--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C",[929],{"type":46,"value":930}," 100",{"type":40,"tag":491,"props":932,"children":933},{"style":519},[934],{"type":46,"value":935},",\n",{"type":40,"tag":491,"props":937,"children":939},{"class":493,"line":938},11,[940,945,949,953,958,962,967,971,975,979,984],{"type":40,"tag":491,"props":941,"children":942},{"style":647},[943],{"type":46,"value":944},"    cursor",{"type":40,"tag":491,"props":946,"children":947},{"style":519},[948],{"type":46,"value":655},{"type":40,"tag":491,"props":950,"children":951},{"style":513},[952],{"type":46,"value":779},{"type":40,"tag":491,"props":954,"children":955},{"style":519},[956],{"type":46,"value":957}," ?",{"type":40,"tag":491,"props":959,"children":960},{"style":519},[961],{"type":46,"value":660},{"type":40,"tag":491,"props":963,"children":964},{"style":647},[965],{"type":46,"value":966}," id",{"type":40,"tag":491,"props":968,"children":969},{"style":519},[970],{"type":46,"value":655},{"type":40,"tag":491,"props":972,"children":973},{"style":513},[974],{"type":46,"value":779},{"type":40,"tag":491,"props":976,"children":977},{"style":519},[978],{"type":46,"value":690},{"type":40,"tag":491,"props":980,"children":981},{"style":519},[982],{"type":46,"value":983}," :",{"type":40,"tag":491,"props":985,"children":986},{"style":519},[987],{"type":46,"value":988}," undefined,\n",{"type":40,"tag":491,"props":990,"children":992},{"class":493,"line":991},12,[993,998,1002,1006,1010,1014,1018,1023,1027],{"type":40,"tag":491,"props":994,"children":995},{"style":647},[996],{"type":46,"value":997},"    orderBy",{"type":40,"tag":491,"props":999,"children":1000},{"style":519},[1001],{"type":46,"value":655},{"type":40,"tag":491,"props":1003,"children":1004},{"style":519},[1005],{"type":46,"value":660},{"type":40,"tag":491,"props":1007,"children":1008},{"style":647},[1009],{"type":46,"value":966},{"type":40,"tag":491,"props":1011,"children":1012},{"style":519},[1013],{"type":46,"value":655},{"type":40,"tag":491,"props":1015,"children":1016},{"style":519},[1017],{"type":46,"value":674},{"type":40,"tag":491,"props":1019,"children":1020},{"style":677},[1021],{"type":46,"value":1022},"asc",{"type":40,"tag":491,"props":1024,"children":1025},{"style":519},[1026],{"type":46,"value":685},{"type":40,"tag":491,"props":1028,"children":1029},{"style":519},[1030],{"type":46,"value":911},{"type":40,"tag":491,"props":1032,"children":1034},{"class":493,"line":1033},13,[1035,1040,1044],{"type":40,"tag":491,"props":1036,"children":1037},{"style":519},[1038],{"type":46,"value":1039},"  }",{"type":40,"tag":491,"props":1041,"children":1042},{"style":647},[1043],{"type":46,"value":699},{"type":40,"tag":491,"props":1045,"children":1046},{"style":519},[1047],{"type":46,"value":569},{"type":40,"tag":491,"props":1049,"children":1051},{"class":493,"line":1050},14,[1052,1057,1062,1066,1071,1076,1080,1085,1090,1094,1098,1102,1106],{"type":40,"tag":491,"props":1053,"children":1054},{"style":609},[1055],{"type":46,"value":1056},"  for",{"type":40,"tag":491,"props":1058,"children":1059},{"style":647},[1060],{"type":46,"value":1061}," (",{"type":40,"tag":491,"props":1063,"children":1064},{"style":507},[1065],{"type":46,"value":510},{"type":40,"tag":491,"props":1067,"children":1068},{"style":513},[1069],{"type":46,"value":1070}," org",{"type":40,"tag":491,"props":1072,"children":1073},{"style":519},[1074],{"type":46,"value":1075}," of",{"type":40,"tag":491,"props":1077,"children":1078},{"style":513},[1079],{"type":46,"value":831},{"type":40,"tag":491,"props":1081,"children":1082},{"style":647},[1083],{"type":46,"value":1084},") ",{"type":40,"tag":491,"props":1086,"children":1087},{"style":609},[1088],{"type":46,"value":1089},"await",{"type":40,"tag":491,"props":1091,"children":1092},{"style":535},[1093],{"type":46,"value":738},{"type":40,"tag":491,"props":1095,"children":1096},{"style":647},[1097],{"type":46,"value":543},{"type":40,"tag":491,"props":1099,"children":1100},{"style":513},[1101],{"type":46,"value":729},{"type":40,"tag":491,"props":1103,"children":1104},{"style":647},[1105],{"type":46,"value":699},{"type":40,"tag":491,"props":1107,"children":1108},{"style":519},[1109],{"type":46,"value":569},{"type":40,"tag":491,"props":1111,"children":1113},{"class":493,"line":1112},15,[1114,1119,1123,1127,1131,1136,1141,1145,1149,1153,1158,1163,1167,1171,1176,1181,1186,1190,1195,1199],{"type":40,"tag":491,"props":1115,"children":1116},{"style":513},[1117],{"type":46,"value":1118},"  cursor",{"type":40,"tag":491,"props":1120,"children":1121},{"style":519},[1122],{"type":46,"value":836},{"type":40,"tag":491,"props":1124,"children":1125},{"style":513},[1126],{"type":46,"value":831},{"type":40,"tag":491,"props":1128,"children":1129},{"style":519},[1130],{"type":46,"value":532},{"type":40,"tag":491,"props":1132,"children":1133},{"style":513},[1134],{"type":46,"value":1135},"length",{"type":40,"tag":491,"props":1137,"children":1138},{"style":519},[1139],{"type":46,"value":1140}," ===",{"type":40,"tag":491,"props":1142,"children":1143},{"style":927},[1144],{"type":46,"value":930},{"type":40,"tag":491,"props":1146,"children":1147},{"style":519},[1148],{"type":46,"value":957},{"type":40,"tag":491,"props":1150,"children":1151},{"style":513},[1152],{"type":46,"value":831},{"type":40,"tag":491,"props":1154,"children":1155},{"style":647},[1156],{"type":46,"value":1157},"[",{"type":40,"tag":491,"props":1159,"children":1160},{"style":513},[1161],{"type":46,"value":1162},"batch",{"type":40,"tag":491,"props":1164,"children":1165},{"style":519},[1166],{"type":46,"value":532},{"type":40,"tag":491,"props":1168,"children":1169},{"style":513},[1170],{"type":46,"value":1135},{"type":40,"tag":491,"props":1172,"children":1173},{"style":519},[1174],{"type":46,"value":1175}," -",{"type":40,"tag":491,"props":1177,"children":1178},{"style":927},[1179],{"type":46,"value":1180}," 1",{"type":40,"tag":491,"props":1182,"children":1183},{"style":647},[1184],{"type":46,"value":1185},"]",{"type":40,"tag":491,"props":1187,"children":1188},{"style":519},[1189],{"type":46,"value":532},{"type":40,"tag":491,"props":1191,"children":1192},{"style":513},[1193],{"type":46,"value":1194},"id",{"type":40,"tag":491,"props":1196,"children":1197},{"style":519},[1198],{"type":46,"value":983},{"type":40,"tag":491,"props":1200,"children":1201},{"style":519},[1202],{"type":46,"value":1203}," undefined;\n",{"type":40,"tag":491,"props":1205,"children":1207},{"class":493,"line":1206},16,[1208,1213,1218,1223],{"type":40,"tag":491,"props":1209,"children":1210},{"style":519},[1211],{"type":46,"value":1212},"}",{"type":40,"tag":491,"props":1214,"children":1215},{"style":609},[1216],{"type":46,"value":1217}," while",{"type":40,"tag":491,"props":1219,"children":1220},{"style":513},[1221],{"type":46,"value":1222}," (cursor)",{"type":40,"tag":491,"props":1224,"children":1225},{"style":519},[1226],{"type":46,"value":569},{"type":40,"tag":473,"props":1228,"children":1230},{"id":1229},"aggregate-in-the-database-not-in-memory",[1231],{"type":46,"value":1232},"Aggregate in the database, not in memory",{"type":40,"tag":480,"props":1234,"children":1236},{"className":482,"code":1235,"language":484,"meta":485,"style":485},"\u002F\u002F Dangerous: loads all events into memory to count them\nconst events = await getAllEvents(orgId);\nconst counts = new Map\u003Cstring, number>();\nfor (const e of events) counts.set(e.type, (counts.get(e.type) || 0) + 1);\n\n\u002F\u002F Safe: push aggregation to the database\nconst counts = await db.$queryRaw`\n  SELECT event_type, COUNT(*) as count\n  FROM events WHERE org_id = ${orgId}\n  GROUP BY event_type\n`;\n",[1237],{"type":40,"tag":276,"props":1238,"children":1239},{"__ignoreMap":485},[1240,1248,1282,1342,1458,1465,1473,1510,1518,1541,1549],{"type":40,"tag":491,"props":1241,"children":1242},{"class":493,"line":27},[1243],{"type":40,"tag":491,"props":1244,"children":1245},{"style":497},[1246],{"type":46,"value":1247},"\u002F\u002F Dangerous: loads all events into memory to count them\n",{"type":40,"tag":491,"props":1249,"children":1250},{"class":493,"line":503},[1251,1255,1260,1264,1268,1273,1278],{"type":40,"tag":491,"props":1252,"children":1253},{"style":507},[1254],{"type":46,"value":510},{"type":40,"tag":491,"props":1256,"children":1257},{"style":513},[1258],{"type":46,"value":1259}," events ",{"type":40,"tag":491,"props":1261,"children":1262},{"style":519},[1263],{"type":46,"value":522},{"type":40,"tag":491,"props":1265,"children":1266},{"style":609},[1267],{"type":46,"value":612},{"type":40,"tag":491,"props":1269,"children":1270},{"style":535},[1271],{"type":46,"value":1272}," getAllEvents",{"type":40,"tag":491,"props":1274,"children":1275},{"style":513},[1276],{"type":46,"value":1277},"(orgId)",{"type":40,"tag":491,"props":1279,"children":1280},{"style":519},[1281],{"type":46,"value":569},{"type":40,"tag":491,"props":1283,"children":1284},{"class":493,"line":23},[1285,1289,1294,1298,1303,1308,1313,1318,1323,1328,1333,1338],{"type":40,"tag":491,"props":1286,"children":1287},{"style":507},[1288],{"type":46,"value":510},{"type":40,"tag":491,"props":1290,"children":1291},{"style":513},[1292],{"type":46,"value":1293}," counts ",{"type":40,"tag":491,"props":1295,"children":1296},{"style":519},[1297],{"type":46,"value":522},{"type":40,"tag":491,"props":1299,"children":1300},{"style":519},[1301],{"type":46,"value":1302}," new",{"type":40,"tag":491,"props":1304,"children":1305},{"style":535},[1306],{"type":46,"value":1307}," Map",{"type":40,"tag":491,"props":1309,"children":1310},{"style":519},[1311],{"type":46,"value":1312},"\u003C",{"type":40,"tag":491,"props":1314,"children":1315},{"style":786},[1316],{"type":46,"value":1317},"string",{"type":40,"tag":491,"props":1319,"children":1320},{"style":519},[1321],{"type":46,"value":1322},",",{"type":40,"tag":491,"props":1324,"children":1325},{"style":786},[1326],{"type":46,"value":1327}," number",{"type":40,"tag":491,"props":1329,"children":1330},{"style":519},[1331],{"type":46,"value":1332},">",{"type":40,"tag":491,"props":1334,"children":1335},{"style":513},[1336],{"type":46,"value":1337},"()",{"type":40,"tag":491,"props":1339,"children":1340},{"style":519},[1341],{"type":46,"value":569},{"type":40,"tag":491,"props":1343,"children":1344},{"class":493,"line":750},[1345,1350,1354,1358,1363,1368,1373,1377,1382,1387,1391,1396,1400,1405,1409,1414,1418,1422,1427,1432,1437,1441,1446,1450,1454],{"type":40,"tag":491,"props":1346,"children":1347},{"style":609},[1348],{"type":46,"value":1349},"for",{"type":40,"tag":491,"props":1351,"children":1352},{"style":513},[1353],{"type":46,"value":1061},{"type":40,"tag":491,"props":1355,"children":1356},{"style":507},[1357],{"type":46,"value":510},{"type":40,"tag":491,"props":1359,"children":1360},{"style":513},[1361],{"type":46,"value":1362}," e ",{"type":40,"tag":491,"props":1364,"children":1365},{"style":519},[1366],{"type":46,"value":1367},"of",{"type":40,"tag":491,"props":1369,"children":1370},{"style":513},[1371],{"type":46,"value":1372}," events) counts",{"type":40,"tag":491,"props":1374,"children":1375},{"style":519},[1376],{"type":46,"value":532},{"type":40,"tag":491,"props":1378,"children":1379},{"style":535},[1380],{"type":46,"value":1381},"set",{"type":40,"tag":491,"props":1383,"children":1384},{"style":513},[1385],{"type":46,"value":1386},"(e",{"type":40,"tag":491,"props":1388,"children":1389},{"style":519},[1390],{"type":46,"value":532},{"type":40,"tag":491,"props":1392,"children":1393},{"style":513},[1394],{"type":46,"value":1395},"type",{"type":40,"tag":491,"props":1397,"children":1398},{"style":519},[1399],{"type":46,"value":1322},{"type":40,"tag":491,"props":1401,"children":1402},{"style":513},[1403],{"type":46,"value":1404}," (counts",{"type":40,"tag":491,"props":1406,"children":1407},{"style":519},[1408],{"type":46,"value":532},{"type":40,"tag":491,"props":1410,"children":1411},{"style":535},[1412],{"type":46,"value":1413},"get",{"type":40,"tag":491,"props":1415,"children":1416},{"style":513},[1417],{"type":46,"value":1386},{"type":40,"tag":491,"props":1419,"children":1420},{"style":519},[1421],{"type":46,"value":532},{"type":40,"tag":491,"props":1423,"children":1424},{"style":513},[1425],{"type":46,"value":1426},"type) ",{"type":40,"tag":491,"props":1428,"children":1429},{"style":519},[1430],{"type":46,"value":1431},"||",{"type":40,"tag":491,"props":1433,"children":1434},{"style":927},[1435],{"type":46,"value":1436}," 0",{"type":40,"tag":491,"props":1438,"children":1439},{"style":513},[1440],{"type":46,"value":1084},{"type":40,"tag":491,"props":1442,"children":1443},{"style":519},[1444],{"type":46,"value":1445},"+",{"type":40,"tag":491,"props":1447,"children":1448},{"style":927},[1449],{"type":46,"value":1180},{"type":40,"tag":491,"props":1451,"children":1452},{"style":513},[1453],{"type":46,"value":699},{"type":40,"tag":491,"props":1455,"children":1456},{"style":519},[1457],{"type":46,"value":569},{"type":40,"tag":491,"props":1459,"children":1460},{"class":493,"line":759},[1461],{"type":40,"tag":491,"props":1462,"children":1463},{"emptyLinePlaceholder":416},[1464],{"type":46,"value":756},{"type":40,"tag":491,"props":1466,"children":1467},{"class":493,"line":768},[1468],{"type":40,"tag":491,"props":1469,"children":1470},{"style":497},[1471],{"type":46,"value":1472},"\u002F\u002F Safe: push aggregation to the database\n",{"type":40,"tag":491,"props":1474,"children":1475},{"class":493,"line":806},[1476,1480,1484,1488,1492,1496,1500,1505],{"type":40,"tag":491,"props":1477,"children":1478},{"style":507},[1479],{"type":46,"value":510},{"type":40,"tag":491,"props":1481,"children":1482},{"style":513},[1483],{"type":46,"value":1293},{"type":40,"tag":491,"props":1485,"children":1486},{"style":519},[1487],{"type":46,"value":522},{"type":40,"tag":491,"props":1489,"children":1490},{"style":609},[1491],{"type":46,"value":612},{"type":40,"tag":491,"props":1493,"children":1494},{"style":513},[1495],{"type":46,"value":617},{"type":40,"tag":491,"props":1497,"children":1498},{"style":519},[1499],{"type":46,"value":532},{"type":40,"tag":491,"props":1501,"children":1502},{"style":535},[1503],{"type":46,"value":1504},"$queryRaw",{"type":40,"tag":491,"props":1506,"children":1507},{"style":519},[1508],{"type":46,"value":1509},"`\n",{"type":40,"tag":491,"props":1511,"children":1512},{"class":493,"line":820},[1513],{"type":40,"tag":491,"props":1514,"children":1515},{"style":677},[1516],{"type":46,"value":1517},"  SELECT event_type, COUNT(*) as count\n",{"type":40,"tag":491,"props":1519,"children":1520},{"class":493,"line":872},[1521,1526,1531,1536],{"type":40,"tag":491,"props":1522,"children":1523},{"style":677},[1524],{"type":46,"value":1525},"  FROM events WHERE org_id = ",{"type":40,"tag":491,"props":1527,"children":1528},{"style":519},[1529],{"type":46,"value":1530},"${",{"type":40,"tag":491,"props":1532,"children":1533},{"style":513},[1534],{"type":46,"value":1535},"orgId",{"type":40,"tag":491,"props":1537,"children":1538},{"style":519},[1539],{"type":46,"value":1540},"}\n",{"type":40,"tag":491,"props":1542,"children":1543},{"class":493,"line":914},[1544],{"type":40,"tag":491,"props":1545,"children":1546},{"style":677},[1547],{"type":46,"value":1548},"  GROUP BY event_type\n",{"type":40,"tag":491,"props":1550,"children":1551},{"class":493,"line":938},[1552,1557],{"type":40,"tag":491,"props":1553,"children":1554},{"style":519},[1555],{"type":46,"value":1556},"`",{"type":40,"tag":491,"props":1558,"children":1559},{"style":519},[1560],{"type":46,"value":569},{"type":40,"tag":473,"props":1562,"children":1564},{"id":1563},"bound-fan-out-with-queuing",[1565],{"type":46,"value":1566},"Bound fan-out with queuing",{"type":40,"tag":480,"props":1568,"children":1570},{"className":482,"code":1569,"language":484,"meta":485,"style":485},"\u002F\u002F Dangerous: unbounded concurrent fan-out\nconst members = await getTeamMembers(teamId);\nawait Promise.all(members.map(m => sendNotification(m.id, message)));\n\n\u002F\u002F Safe: check cardinality, branch strategy\nconst count = await getTeamMemberCount(teamId);\nif (count > DIRECT_THRESHOLD) {\n  await enqueueJob(\"notify-team\", { teamId, message }); \u002F\u002F batched in background\n} else {\n  const members = await getTeamMembers(teamId);\n  await Promise.all(members.map(m => sendNotification(m.id, message)));\n}\n",[1571],{"type":40,"tag":276,"props":1572,"children":1573},{"__ignoreMap":485},[1574,1582,1616,1694,1701,1709,1742,1768,1838,1854,1895,1980],{"type":40,"tag":491,"props":1575,"children":1576},{"class":493,"line":27},[1577],{"type":40,"tag":491,"props":1578,"children":1579},{"style":497},[1580],{"type":46,"value":1581},"\u002F\u002F Dangerous: unbounded concurrent fan-out\n",{"type":40,"tag":491,"props":1583,"children":1584},{"class":493,"line":503},[1585,1589,1594,1598,1602,1607,1612],{"type":40,"tag":491,"props":1586,"children":1587},{"style":507},[1588],{"type":46,"value":510},{"type":40,"tag":491,"props":1590,"children":1591},{"style":513},[1592],{"type":46,"value":1593}," members ",{"type":40,"tag":491,"props":1595,"children":1596},{"style":519},[1597],{"type":46,"value":522},{"type":40,"tag":491,"props":1599,"children":1600},{"style":609},[1601],{"type":46,"value":612},{"type":40,"tag":491,"props":1603,"children":1604},{"style":535},[1605],{"type":46,"value":1606}," getTeamMembers",{"type":40,"tag":491,"props":1608,"children":1609},{"style":513},[1610],{"type":46,"value":1611},"(teamId)",{"type":40,"tag":491,"props":1613,"children":1614},{"style":519},[1615],{"type":46,"value":569},{"type":40,"tag":491,"props":1617,"children":1618},{"class":493,"line":23},[1619,1623,1628,1632,1637,1642,1646,1650,1654,1659,1663,1668,1673,1677,1681,1685,1690],{"type":40,"tag":491,"props":1620,"children":1621},{"style":609},[1622],{"type":46,"value":1089},{"type":40,"tag":491,"props":1624,"children":1625},{"style":786},[1626],{"type":46,"value":1627}," Promise",{"type":40,"tag":491,"props":1629,"children":1630},{"style":519},[1631],{"type":46,"value":532},{"type":40,"tag":491,"props":1633,"children":1634},{"style":535},[1635],{"type":46,"value":1636},"all",{"type":40,"tag":491,"props":1638,"children":1639},{"style":513},[1640],{"type":46,"value":1641},"(members",{"type":40,"tag":491,"props":1643,"children":1644},{"style":519},[1645],{"type":46,"value":532},{"type":40,"tag":491,"props":1647,"children":1648},{"style":535},[1649],{"type":46,"value":538},{"type":40,"tag":491,"props":1651,"children":1652},{"style":513},[1653],{"type":46,"value":543},{"type":40,"tag":491,"props":1655,"children":1656},{"style":546},[1657],{"type":46,"value":1658},"m",{"type":40,"tag":491,"props":1660,"children":1661},{"style":507},[1662],{"type":46,"value":554},{"type":40,"tag":491,"props":1664,"children":1665},{"style":535},[1666],{"type":46,"value":1667}," sendNotification",{"type":40,"tag":491,"props":1669,"children":1670},{"style":513},[1671],{"type":46,"value":1672},"(m",{"type":40,"tag":491,"props":1674,"children":1675},{"style":519},[1676],{"type":46,"value":532},{"type":40,"tag":491,"props":1678,"children":1679},{"style":513},[1680],{"type":46,"value":1194},{"type":40,"tag":491,"props":1682,"children":1683},{"style":519},[1684],{"type":46,"value":1322},{"type":40,"tag":491,"props":1686,"children":1687},{"style":513},[1688],{"type":46,"value":1689}," message)))",{"type":40,"tag":491,"props":1691,"children":1692},{"style":519},[1693],{"type":46,"value":569},{"type":40,"tag":491,"props":1695,"children":1696},{"class":493,"line":750},[1697],{"type":40,"tag":491,"props":1698,"children":1699},{"emptyLinePlaceholder":416},[1700],{"type":46,"value":756},{"type":40,"tag":491,"props":1702,"children":1703},{"class":493,"line":759},[1704],{"type":40,"tag":491,"props":1705,"children":1706},{"style":497},[1707],{"type":46,"value":1708},"\u002F\u002F Safe: check cardinality, branch strategy\n",{"type":40,"tag":491,"props":1710,"children":1711},{"class":493,"line":768},[1712,1716,1721,1725,1729,1734,1738],{"type":40,"tag":491,"props":1713,"children":1714},{"style":507},[1715],{"type":46,"value":510},{"type":40,"tag":491,"props":1717,"children":1718},{"style":513},[1719],{"type":46,"value":1720}," count ",{"type":40,"tag":491,"props":1722,"children":1723},{"style":519},[1724],{"type":46,"value":522},{"type":40,"tag":491,"props":1726,"children":1727},{"style":609},[1728],{"type":46,"value":612},{"type":40,"tag":491,"props":1730,"children":1731},{"style":535},[1732],{"type":46,"value":1733}," getTeamMemberCount",{"type":40,"tag":491,"props":1735,"children":1736},{"style":513},[1737],{"type":46,"value":1611},{"type":40,"tag":491,"props":1739,"children":1740},{"style":519},[1741],{"type":46,"value":569},{"type":40,"tag":491,"props":1743,"children":1744},{"class":493,"line":806},[1745,1750,1755,1759,1764],{"type":40,"tag":491,"props":1746,"children":1747},{"style":609},[1748],{"type":46,"value":1749},"if",{"type":40,"tag":491,"props":1751,"children":1752},{"style":513},[1753],{"type":46,"value":1754}," (count ",{"type":40,"tag":491,"props":1756,"children":1757},{"style":519},[1758],{"type":46,"value":1332},{"type":40,"tag":491,"props":1760,"children":1761},{"style":513},[1762],{"type":46,"value":1763}," DIRECT_THRESHOLD) ",{"type":40,"tag":491,"props":1765,"children":1766},{"style":519},[1767],{"type":46,"value":869},{"type":40,"tag":491,"props":1769,"children":1770},{"class":493,"line":820},[1771,1776,1781,1785,1789,1794,1798,1802,1806,1811,1815,1820,1824,1828,1833],{"type":40,"tag":491,"props":1772,"children":1773},{"style":609},[1774],{"type":46,"value":1775},"  await",{"type":40,"tag":491,"props":1777,"children":1778},{"style":535},[1779],{"type":46,"value":1780}," enqueueJob",{"type":40,"tag":491,"props":1782,"children":1783},{"style":647},[1784],{"type":46,"value":543},{"type":40,"tag":491,"props":1786,"children":1787},{"style":519},[1788],{"type":46,"value":685},{"type":40,"tag":491,"props":1790,"children":1791},{"style":677},[1792],{"type":46,"value":1793},"notify-team",{"type":40,"tag":491,"props":1795,"children":1796},{"style":519},[1797],{"type":46,"value":685},{"type":40,"tag":491,"props":1799,"children":1800},{"style":519},[1801],{"type":46,"value":1322},{"type":40,"tag":491,"props":1803,"children":1804},{"style":519},[1805],{"type":46,"value":660},{"type":40,"tag":491,"props":1807,"children":1808},{"style":513},[1809],{"type":46,"value":1810}," teamId",{"type":40,"tag":491,"props":1812,"children":1813},{"style":519},[1814],{"type":46,"value":1322},{"type":40,"tag":491,"props":1816,"children":1817},{"style":513},[1818],{"type":46,"value":1819}," message",{"type":40,"tag":491,"props":1821,"children":1822},{"style":519},[1823],{"type":46,"value":690},{"type":40,"tag":491,"props":1825,"children":1826},{"style":647},[1827],{"type":46,"value":699},{"type":40,"tag":491,"props":1829,"children":1830},{"style":519},[1831],{"type":46,"value":1832},";",{"type":40,"tag":491,"props":1834,"children":1835},{"style":497},[1836],{"type":46,"value":1837}," \u002F\u002F batched in background\n",{"type":40,"tag":491,"props":1839,"children":1840},{"class":493,"line":872},[1841,1845,1850],{"type":40,"tag":491,"props":1842,"children":1843},{"style":519},[1844],{"type":46,"value":1212},{"type":40,"tag":491,"props":1846,"children":1847},{"style":609},[1848],{"type":46,"value":1849}," else",{"type":40,"tag":491,"props":1851,"children":1852},{"style":519},[1853],{"type":46,"value":817},{"type":40,"tag":491,"props":1855,"children":1856},{"class":493,"line":914},[1857,1861,1866,1870,1874,1878,1882,1887,1891],{"type":40,"tag":491,"props":1858,"children":1859},{"style":507},[1860],{"type":46,"value":826},{"type":40,"tag":491,"props":1862,"children":1863},{"style":513},[1864],{"type":46,"value":1865}," members",{"type":40,"tag":491,"props":1867,"children":1868},{"style":519},[1869],{"type":46,"value":836},{"type":40,"tag":491,"props":1871,"children":1872},{"style":609},[1873],{"type":46,"value":612},{"type":40,"tag":491,"props":1875,"children":1876},{"style":535},[1877],{"type":46,"value":1606},{"type":40,"tag":491,"props":1879,"children":1880},{"style":647},[1881],{"type":46,"value":543},{"type":40,"tag":491,"props":1883,"children":1884},{"style":513},[1885],{"type":46,"value":1886},"teamId",{"type":40,"tag":491,"props":1888,"children":1889},{"style":647},[1890],{"type":46,"value":699},{"type":40,"tag":491,"props":1892,"children":1893},{"style":519},[1894],{"type":46,"value":569},{"type":40,"tag":491,"props":1896,"children":1897},{"class":493,"line":938},[1898,1902,1906,1910,1914,1918,1923,1927,1931,1935,1939,1943,1947,1951,1955,1959,1963,1967,1971,1976],{"type":40,"tag":491,"props":1899,"children":1900},{"style":609},[1901],{"type":46,"value":1775},{"type":40,"tag":491,"props":1903,"children":1904},{"style":786},[1905],{"type":46,"value":1627},{"type":40,"tag":491,"props":1907,"children":1908},{"style":519},[1909],{"type":46,"value":532},{"type":40,"tag":491,"props":1911,"children":1912},{"style":535},[1913],{"type":46,"value":1636},{"type":40,"tag":491,"props":1915,"children":1916},{"style":647},[1917],{"type":46,"value":543},{"type":40,"tag":491,"props":1919,"children":1920},{"style":513},[1921],{"type":46,"value":1922},"members",{"type":40,"tag":491,"props":1924,"children":1925},{"style":519},[1926],{"type":46,"value":532},{"type":40,"tag":491,"props":1928,"children":1929},{"style":535},[1930],{"type":46,"value":538},{"type":40,"tag":491,"props":1932,"children":1933},{"style":647},[1934],{"type":46,"value":543},{"type":40,"tag":491,"props":1936,"children":1937},{"style":546},[1938],{"type":46,"value":1658},{"type":40,"tag":491,"props":1940,"children":1941},{"style":507},[1942],{"type":46,"value":554},{"type":40,"tag":491,"props":1944,"children":1945},{"style":535},[1946],{"type":46,"value":1667},{"type":40,"tag":491,"props":1948,"children":1949},{"style":647},[1950],{"type":46,"value":543},{"type":40,"tag":491,"props":1952,"children":1953},{"style":513},[1954],{"type":46,"value":1658},{"type":40,"tag":491,"props":1956,"children":1957},{"style":519},[1958],{"type":46,"value":532},{"type":40,"tag":491,"props":1960,"children":1961},{"style":513},[1962],{"type":46,"value":1194},{"type":40,"tag":491,"props":1964,"children":1965},{"style":519},[1966],{"type":46,"value":1322},{"type":40,"tag":491,"props":1968,"children":1969},{"style":513},[1970],{"type":46,"value":1819},{"type":40,"tag":491,"props":1972,"children":1973},{"style":647},[1974],{"type":46,"value":1975},")))",{"type":40,"tag":491,"props":1977,"children":1978},{"style":519},[1979],{"type":46,"value":569},{"type":40,"tag":491,"props":1981,"children":1982},{"class":493,"line":991},[1983],{"type":40,"tag":491,"props":1984,"children":1985},{"style":519},[1986],{"type":46,"value":1540},{"type":40,"tag":473,"props":1988,"children":1990},{"id":1989},"never-create-unbounded-per-entity-resources",[1991],{"type":46,"value":1992},"Never create unbounded per-entity resources",{"type":40,"tag":480,"props":1994,"children":1996},{"className":482,"code":1995,"language":484,"meta":485,"style":485},"\u002F\u002F Dangerous: one timer per session, never cleaned up\nfor (const session of sessions) {\n  setInterval(() => pingSession(session.id), 30_000);\n}\n\n\u002F\u002F Safe: single timer that iterates, or use a bounded pool\nconst sessionPinger = setInterval(async () => {\n  const activeSessions = await getActiveSessions({ limit: 1000 });\n  for (const session of activeSessions) await pingSession(session.id);\n}, 30_000);\n",[1997],{"type":40,"tag":276,"props":1998,"children":1999},{"__ignoreMap":485},[2000,2008,2041,2104,2111,2118,2126,2169,2228,2292],{"type":40,"tag":491,"props":2001,"children":2002},{"class":493,"line":27},[2003],{"type":40,"tag":491,"props":2004,"children":2005},{"style":497},[2006],{"type":46,"value":2007},"\u002F\u002F Dangerous: one timer per session, never cleaned up\n",{"type":40,"tag":491,"props":2009,"children":2010},{"class":493,"line":503},[2011,2015,2019,2023,2028,2032,2037],{"type":40,"tag":491,"props":2012,"children":2013},{"style":609},[2014],{"type":46,"value":1349},{"type":40,"tag":491,"props":2016,"children":2017},{"style":513},[2018],{"type":46,"value":1061},{"type":40,"tag":491,"props":2020,"children":2021},{"style":507},[2022],{"type":46,"value":510},{"type":40,"tag":491,"props":2024,"children":2025},{"style":513},[2026],{"type":46,"value":2027}," session ",{"type":40,"tag":491,"props":2029,"children":2030},{"style":519},[2031],{"type":46,"value":1367},{"type":40,"tag":491,"props":2033,"children":2034},{"style":513},[2035],{"type":46,"value":2036}," sessions) ",{"type":40,"tag":491,"props":2038,"children":2039},{"style":519},[2040],{"type":46,"value":869},{"type":40,"tag":491,"props":2042,"children":2043},{"class":493,"line":23},[2044,2049,2053,2057,2061,2066,2070,2075,2079,2083,2087,2091,2096,2100],{"type":40,"tag":491,"props":2045,"children":2046},{"style":535},[2047],{"type":46,"value":2048},"  setInterval",{"type":40,"tag":491,"props":2050,"children":2051},{"style":647},[2052],{"type":46,"value":543},{"type":40,"tag":491,"props":2054,"children":2055},{"style":519},[2056],{"type":46,"value":1337},{"type":40,"tag":491,"props":2058,"children":2059},{"style":507},[2060],{"type":46,"value":554},{"type":40,"tag":491,"props":2062,"children":2063},{"style":535},[2064],{"type":46,"value":2065}," pingSession",{"type":40,"tag":491,"props":2067,"children":2068},{"style":647},[2069],{"type":46,"value":543},{"type":40,"tag":491,"props":2071,"children":2072},{"style":513},[2073],{"type":46,"value":2074},"session",{"type":40,"tag":491,"props":2076,"children":2077},{"style":519},[2078],{"type":46,"value":532},{"type":40,"tag":491,"props":2080,"children":2081},{"style":513},[2082],{"type":46,"value":1194},{"type":40,"tag":491,"props":2084,"children":2085},{"style":647},[2086],{"type":46,"value":699},{"type":40,"tag":491,"props":2088,"children":2089},{"style":519},[2090],{"type":46,"value":1322},{"type":40,"tag":491,"props":2092,"children":2093},{"style":927},[2094],{"type":46,"value":2095}," 30_000",{"type":40,"tag":491,"props":2097,"children":2098},{"style":647},[2099],{"type":46,"value":699},{"type":40,"tag":491,"props":2101,"children":2102},{"style":519},[2103],{"type":46,"value":569},{"type":40,"tag":491,"props":2105,"children":2106},{"class":493,"line":750},[2107],{"type":40,"tag":491,"props":2108,"children":2109},{"style":519},[2110],{"type":46,"value":1540},{"type":40,"tag":491,"props":2112,"children":2113},{"class":493,"line":759},[2114],{"type":40,"tag":491,"props":2115,"children":2116},{"emptyLinePlaceholder":416},[2117],{"type":46,"value":756},{"type":40,"tag":491,"props":2119,"children":2120},{"class":493,"line":768},[2121],{"type":40,"tag":491,"props":2122,"children":2123},{"style":497},[2124],{"type":46,"value":2125},"\u002F\u002F Safe: single timer that iterates, or use a bounded pool\n",{"type":40,"tag":491,"props":2127,"children":2128},{"class":493,"line":806},[2129,2133,2138,2142,2147,2151,2156,2161,2165],{"type":40,"tag":491,"props":2130,"children":2131},{"style":507},[2132],{"type":46,"value":510},{"type":40,"tag":491,"props":2134,"children":2135},{"style":513},[2136],{"type":46,"value":2137}," sessionPinger ",{"type":40,"tag":491,"props":2139,"children":2140},{"style":519},[2141],{"type":46,"value":522},{"type":40,"tag":491,"props":2143,"children":2144},{"style":535},[2145],{"type":46,"value":2146}," setInterval",{"type":40,"tag":491,"props":2148,"children":2149},{"style":513},[2150],{"type":46,"value":543},{"type":40,"tag":491,"props":2152,"children":2153},{"style":507},[2154],{"type":46,"value":2155},"async",{"type":40,"tag":491,"props":2157,"children":2158},{"style":519},[2159],{"type":46,"value":2160}," ()",{"type":40,"tag":491,"props":2162,"children":2163},{"style":507},[2164],{"type":46,"value":554},{"type":40,"tag":491,"props":2166,"children":2167},{"style":519},[2168],{"type":46,"value":817},{"type":40,"tag":491,"props":2170,"children":2171},{"class":493,"line":820},[2172,2176,2181,2185,2189,2194,2198,2202,2207,2211,2216,2220,2224],{"type":40,"tag":491,"props":2173,"children":2174},{"style":507},[2175],{"type":46,"value":826},{"type":40,"tag":491,"props":2177,"children":2178},{"style":513},[2179],{"type":46,"value":2180}," activeSessions",{"type":40,"tag":491,"props":2182,"children":2183},{"style":519},[2184],{"type":46,"value":836},{"type":40,"tag":491,"props":2186,"children":2187},{"style":609},[2188],{"type":46,"value":612},{"type":40,"tag":491,"props":2190,"children":2191},{"style":535},[2192],{"type":46,"value":2193}," getActiveSessions",{"type":40,"tag":491,"props":2195,"children":2196},{"style":647},[2197],{"type":46,"value":543},{"type":40,"tag":491,"props":2199,"children":2200},{"style":519},[2201],{"type":46,"value":644},{"type":40,"tag":491,"props":2203,"children":2204},{"style":647},[2205],{"type":46,"value":2206}," limit",{"type":40,"tag":491,"props":2208,"children":2209},{"style":519},[2210],{"type":46,"value":655},{"type":40,"tag":491,"props":2212,"children":2213},{"style":927},[2214],{"type":46,"value":2215}," 1000",{"type":40,"tag":491,"props":2217,"children":2218},{"style":519},[2219],{"type":46,"value":690},{"type":40,"tag":491,"props":2221,"children":2222},{"style":647},[2223],{"type":46,"value":699},{"type":40,"tag":491,"props":2225,"children":2226},{"style":519},[2227],{"type":46,"value":569},{"type":40,"tag":491,"props":2229,"children":2230},{"class":493,"line":872},[2231,2235,2239,2243,2248,2252,2256,2260,2264,2268,2272,2276,2280,2284,2288],{"type":40,"tag":491,"props":2232,"children":2233},{"style":609},[2234],{"type":46,"value":1056},{"type":40,"tag":491,"props":2236,"children":2237},{"style":647},[2238],{"type":46,"value":1061},{"type":40,"tag":491,"props":2240,"children":2241},{"style":507},[2242],{"type":46,"value":510},{"type":40,"tag":491,"props":2244,"children":2245},{"style":513},[2246],{"type":46,"value":2247}," session",{"type":40,"tag":491,"props":2249,"children":2250},{"style":519},[2251],{"type":46,"value":1075},{"type":40,"tag":491,"props":2253,"children":2254},{"style":513},[2255],{"type":46,"value":2180},{"type":40,"tag":491,"props":2257,"children":2258},{"style":647},[2259],{"type":46,"value":1084},{"type":40,"tag":491,"props":2261,"children":2262},{"style":609},[2263],{"type":46,"value":1089},{"type":40,"tag":491,"props":2265,"children":2266},{"style":535},[2267],{"type":46,"value":2065},{"type":40,"tag":491,"props":2269,"children":2270},{"style":647},[2271],{"type":46,"value":543},{"type":40,"tag":491,"props":2273,"children":2274},{"style":513},[2275],{"type":46,"value":2074},{"type":40,"tag":491,"props":2277,"children":2278},{"style":519},[2279],{"type":46,"value":532},{"type":40,"tag":491,"props":2281,"children":2282},{"style":513},[2283],{"type":46,"value":1194},{"type":40,"tag":491,"props":2285,"children":2286},{"style":647},[2287],{"type":46,"value":699},{"type":40,"tag":491,"props":2289,"children":2290},{"style":519},[2291],{"type":46,"value":569},{"type":40,"tag":491,"props":2293,"children":2294},{"class":493,"line":914},[2295,2300,2304,2308],{"type":40,"tag":491,"props":2296,"children":2297},{"style":519},[2298],{"type":46,"value":2299},"},",{"type":40,"tag":491,"props":2301,"children":2302},{"style":927},[2303],{"type":46,"value":2095},{"type":40,"tag":491,"props":2305,"children":2306},{"style":513},[2307],{"type":46,"value":699},{"type":40,"tag":491,"props":2309,"children":2310},{"style":519},[2311],{"type":46,"value":569},{"type":40,"tag":473,"props":2313,"children":2315},{"id":2314},"metrics-and-time-series-multiplicative-cardinality",[2316],{"type":46,"value":2317},"Metrics and time series: multiplicative cardinality",{"type":40,"tag":49,"props":2319,"children":2320},{},[2321],{"type":46,"value":2322},"Metric labels and time series are the most common hidden cardinality trap. The total series count is the cross product of every label value combination, and it grows multiplicatively.",{"type":40,"tag":480,"props":2324,"children":2326},{"className":482,"code":2325,"language":484,"meta":485,"style":485},"\u002F\u002F Dangerous: per-tenant metric label. 50,000 tenants x 20 metrics = 1M series.\n\u002F\u002F Prometheus\u002FVictoria\u002FDatadog all choke on high-cardinality labels.\nmetrics.increment(\"api.requests\", { tenant: tenantId, endpoint, method, status });\n\u002F\u002F If tenantId has 50K values, endpoint has 200, method has 5, status has 5:\n\u002F\u002F 50,000 x 200 x 5 x 5 = 250,000,000 unique series. Your monitoring is dead.\n\n\u002F\u002F Safe: use bounded labels only. Aggregate per-tenant metrics separately.\nmetrics.increment(\"api.requests\", { endpoint, method, status }); \u002F\u002F L1 labels only\n\u002F\u002F Per-tenant data goes to a dedicated analytics pipeline (ClickHouse, BigQuery)\n\u002F\u002F that's designed for high-cardinality dimensional queries.\n",[2327],{"type":40,"tag":276,"props":2328,"children":2329},{"__ignoreMap":485},[2330,2338,2346,2441,2449,2457,2464,2472,2548,2556],{"type":40,"tag":491,"props":2331,"children":2332},{"class":493,"line":27},[2333],{"type":40,"tag":491,"props":2334,"children":2335},{"style":497},[2336],{"type":46,"value":2337},"\u002F\u002F Dangerous: per-tenant metric label. 50,000 tenants x 20 metrics = 1M series.\n",{"type":40,"tag":491,"props":2339,"children":2340},{"class":493,"line":503},[2341],{"type":40,"tag":491,"props":2342,"children":2343},{"style":497},[2344],{"type":46,"value":2345},"\u002F\u002F Prometheus\u002FVictoria\u002FDatadog all choke on high-cardinality labels.\n",{"type":40,"tag":491,"props":2347,"children":2348},{"class":493,"line":23},[2349,2354,2358,2363,2367,2371,2376,2380,2384,2388,2393,2397,2402,2406,2411,2415,2420,2424,2429,2433,2437],{"type":40,"tag":491,"props":2350,"children":2351},{"style":513},[2352],{"type":46,"value":2353},"metrics",{"type":40,"tag":491,"props":2355,"children":2356},{"style":519},[2357],{"type":46,"value":532},{"type":40,"tag":491,"props":2359,"children":2360},{"style":535},[2361],{"type":46,"value":2362},"increment",{"type":40,"tag":491,"props":2364,"children":2365},{"style":513},[2366],{"type":46,"value":543},{"type":40,"tag":491,"props":2368,"children":2369},{"style":519},[2370],{"type":46,"value":685},{"type":40,"tag":491,"props":2372,"children":2373},{"style":677},[2374],{"type":46,"value":2375},"api.requests",{"type":40,"tag":491,"props":2377,"children":2378},{"style":519},[2379],{"type":46,"value":685},{"type":40,"tag":491,"props":2381,"children":2382},{"style":519},[2383],{"type":46,"value":1322},{"type":40,"tag":491,"props":2385,"children":2386},{"style":519},[2387],{"type":46,"value":660},{"type":40,"tag":491,"props":2389,"children":2390},{"style":647},[2391],{"type":46,"value":2392}," tenant",{"type":40,"tag":491,"props":2394,"children":2395},{"style":519},[2396],{"type":46,"value":655},{"type":40,"tag":491,"props":2398,"children":2399},{"style":513},[2400],{"type":46,"value":2401}," tenantId",{"type":40,"tag":491,"props":2403,"children":2404},{"style":519},[2405],{"type":46,"value":1322},{"type":40,"tag":491,"props":2407,"children":2408},{"style":513},[2409],{"type":46,"value":2410}," endpoint",{"type":40,"tag":491,"props":2412,"children":2413},{"style":519},[2414],{"type":46,"value":1322},{"type":40,"tag":491,"props":2416,"children":2417},{"style":513},[2418],{"type":46,"value":2419}," method",{"type":40,"tag":491,"props":2421,"children":2422},{"style":519},[2423],{"type":46,"value":1322},{"type":40,"tag":491,"props":2425,"children":2426},{"style":513},[2427],{"type":46,"value":2428}," status ",{"type":40,"tag":491,"props":2430,"children":2431},{"style":519},[2432],{"type":46,"value":1212},{"type":40,"tag":491,"props":2434,"children":2435},{"style":513},[2436],{"type":46,"value":699},{"type":40,"tag":491,"props":2438,"children":2439},{"style":519},[2440],{"type":46,"value":569},{"type":40,"tag":491,"props":2442,"children":2443},{"class":493,"line":750},[2444],{"type":40,"tag":491,"props":2445,"children":2446},{"style":497},[2447],{"type":46,"value":2448},"\u002F\u002F If tenantId has 50K values, endpoint has 200, method has 5, status has 5:\n",{"type":40,"tag":491,"props":2450,"children":2451},{"class":493,"line":759},[2452],{"type":40,"tag":491,"props":2453,"children":2454},{"style":497},[2455],{"type":46,"value":2456},"\u002F\u002F 50,000 x 200 x 5 x 5 = 250,000,000 unique series. Your monitoring is dead.\n",{"type":40,"tag":491,"props":2458,"children":2459},{"class":493,"line":768},[2460],{"type":40,"tag":491,"props":2461,"children":2462},{"emptyLinePlaceholder":416},[2463],{"type":46,"value":756},{"type":40,"tag":491,"props":2465,"children":2466},{"class":493,"line":806},[2467],{"type":40,"tag":491,"props":2468,"children":2469},{"style":497},[2470],{"type":46,"value":2471},"\u002F\u002F Safe: use bounded labels only. Aggregate per-tenant metrics separately.\n",{"type":40,"tag":491,"props":2473,"children":2474},{"class":493,"line":820},[2475,2479,2483,2487,2491,2495,2499,2503,2507,2511,2515,2519,2523,2527,2531,2535,2539,2543],{"type":40,"tag":491,"props":2476,"children":2477},{"style":513},[2478],{"type":46,"value":2353},{"type":40,"tag":491,"props":2480,"children":2481},{"style":519},[2482],{"type":46,"value":532},{"type":40,"tag":491,"props":2484,"children":2485},{"style":535},[2486],{"type":46,"value":2362},{"type":40,"tag":491,"props":2488,"children":2489},{"style":513},[2490],{"type":46,"value":543},{"type":40,"tag":491,"props":2492,"children":2493},{"style":519},[2494],{"type":46,"value":685},{"type":40,"tag":491,"props":2496,"children":2497},{"style":677},[2498],{"type":46,"value":2375},{"type":40,"tag":491,"props":2500,"children":2501},{"style":519},[2502],{"type":46,"value":685},{"type":40,"tag":491,"props":2504,"children":2505},{"style":519},[2506],{"type":46,"value":1322},{"type":40,"tag":491,"props":2508,"children":2509},{"style":519},[2510],{"type":46,"value":660},{"type":40,"tag":491,"props":2512,"children":2513},{"style":513},[2514],{"type":46,"value":2410},{"type":40,"tag":491,"props":2516,"children":2517},{"style":519},[2518],{"type":46,"value":1322},{"type":40,"tag":491,"props":2520,"children":2521},{"style":513},[2522],{"type":46,"value":2419},{"type":40,"tag":491,"props":2524,"children":2525},{"style":519},[2526],{"type":46,"value":1322},{"type":40,"tag":491,"props":2528,"children":2529},{"style":513},[2530],{"type":46,"value":2428},{"type":40,"tag":491,"props":2532,"children":2533},{"style":519},[2534],{"type":46,"value":1212},{"type":40,"tag":491,"props":2536,"children":2537},{"style":513},[2538],{"type":46,"value":699},{"type":40,"tag":491,"props":2540,"children":2541},{"style":519},[2542],{"type":46,"value":1832},{"type":40,"tag":491,"props":2544,"children":2545},{"style":497},[2546],{"type":46,"value":2547}," \u002F\u002F L1 labels only\n",{"type":40,"tag":491,"props":2549,"children":2550},{"class":493,"line":872},[2551],{"type":40,"tag":491,"props":2552,"children":2553},{"style":497},[2554],{"type":46,"value":2555},"\u002F\u002F Per-tenant data goes to a dedicated analytics pipeline (ClickHouse, BigQuery)\n",{"type":40,"tag":491,"props":2557,"children":2558},{"class":493,"line":914},[2559],{"type":40,"tag":491,"props":2560,"children":2561},{"style":497},[2562],{"type":46,"value":2563},"\u002F\u002F that's designed for high-cardinality dimensional queries.\n",{"type":40,"tag":49,"props":2565,"children":2566},{},[2567,2572],{"type":40,"tag":55,"props":2568,"children":2569},{},[2570],{"type":46,"value":2571},"The rule:",{"type":46,"value":2573}," Every metric label must be L1 or L2. If you need per-tenant, per-user, or per-entity metrics, that's an analytics query, not a metric. Route it to a system designed for high-cardinality queries (ClickHouse, BigQuery, Tinybird) rather than a monitoring system (Prometheus, Datadog, Grafana Cloud) that charges per series or collapses under high cardinality.",{"type":40,"tag":61,"props":2575,"children":2577},{"id":2576},"anti-patterns",[2578],{"type":46,"value":2579},"Anti-Patterns",{"type":40,"tag":403,"props":2581,"children":2582},{},[2583,2609,2627,2645,2661],{"type":40,"tag":269,"props":2584,"children":2585},{},[2586,2591,2593,2599,2601,2607],{"type":40,"tag":55,"props":2587,"children":2588},{},[2589],{"type":46,"value":2590},"Loading an unbounded collection into memory",{"type":46,"value":2592}," -- ",{"type":40,"tag":276,"props":2594,"children":2596},{"className":2595},[],[2597],{"type":46,"value":2598},"findMany()",{"type":46,"value":2600}," with no ",{"type":40,"tag":276,"props":2602,"children":2604},{"className":2603},[],[2605],{"type":46,"value":2606},"take",{"type":46,"value":2608},", then filtering or mapping in app code. Filter and bound in the query; paginate L4\u002FL5 sets.",{"type":40,"tag":269,"props":2610,"children":2611},{},[2612,2617,2619,2625],{"type":40,"tag":55,"props":2613,"children":2614},{},[2615],{"type":46,"value":2616},"One resource per entity",{"type":46,"value":2618}," -- a ",{"type":40,"tag":276,"props":2620,"children":2622},{"className":2621},[],[2623],{"type":46,"value":2624},"setInterval",{"type":46,"value":2626},", connection, queue, or goroutine created per item in a loop. Use a single iterating worker or a bounded pool.",{"type":40,"tag":269,"props":2628,"children":2629},{},[2630,2635,2637,2643],{"type":40,"tag":55,"props":2631,"children":2632},{},[2633],{"type":46,"value":2634},"Aggregating in memory",{"type":46,"value":2636}," -- pulling every row to count\u002Fsum\u002Fgroup in app code. Push the aggregation into the database (",{"type":40,"tag":276,"props":2638,"children":2640},{"className":2639},[],[2641],{"type":46,"value":2642},"GROUP BY",{"type":46,"value":2644},").",{"type":40,"tag":269,"props":2646,"children":2647},{},[2648,2653,2654,2659],{"type":40,"tag":55,"props":2649,"children":2650},{},[2651],{"type":46,"value":2652},"Unbounded fan-out",{"type":46,"value":2592},{"type":40,"tag":276,"props":2655,"children":2657},{"className":2656},[],[2658],{"type":46,"value":368},{"type":46,"value":2660}," over a user- or API-sized array. Check the count and branch to a queue past a threshold.",{"type":40,"tag":269,"props":2662,"children":2663},{},[2664,2669],{"type":40,"tag":55,"props":2665,"children":2666},{},[2667],{"type":46,"value":2668},"High-cardinality metric labels",{"type":46,"value":2670}," -- per-tenant\u002Fuser\u002Fentity labels on a monitoring metric. Keep labels L1\u002FL2; route per-entity analytics to a columnar store.",{"type":40,"tag":61,"props":2672,"children":2674},{"id":2673},"related-traps",[2675],{"type":46,"value":2676},"Related Traps",{"type":40,"tag":403,"props":2678,"children":2679},{},[2680,2690,2700,2726],{"type":40,"tag":269,"props":2681,"children":2682},{},[2683,2688],{"type":40,"tag":55,"props":2684,"children":2685},{},[2686],{"type":46,"value":2687},"Denormalization",{"type":46,"value":2689}," -- denormalizing into a high-cardinality set creates write amplification proportional to the set size.",{"type":40,"tag":269,"props":2691,"children":2692},{},[2693,2698],{"type":40,"tag":55,"props":2694,"children":2695},{},[2696],{"type":46,"value":2697},"Backpressure",{"type":46,"value":2699}," -- unbounded fan-out without backpressure collapses under high cardinality.",{"type":40,"tag":269,"props":2701,"children":2702},{},[2703,2708,2710,2716,2718,2724],{"type":40,"tag":55,"props":2704,"children":2705},{},[2706],{"type":46,"value":2707},"Memory Leaks",{"type":46,"value":2709}," -- unbounded ",{"type":40,"tag":276,"props":2711,"children":2713},{"className":2712},[],[2714],{"type":46,"value":2715},"Map",{"type":46,"value":2717},"\u002F",{"type":40,"tag":276,"props":2719,"children":2721},{"className":2720},[],[2722],{"type":46,"value":2723},"Set",{"type":46,"value":2725}," at module scope is both a cardinality trap and a memory leak.",{"type":40,"tag":269,"props":2727,"children":2728},{},[2729,2734],{"type":40,"tag":55,"props":2730,"children":2731},{},[2732],{"type":46,"value":2733},"Streams vs Batch",{"type":46,"value":2735}," -- high cardinality is the forcing function that moves you from batch to streaming.",{"type":40,"tag":2737,"props":2738,"children":2739},"style",{},[2740],{"type":46,"value":2741},"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":2743,"total":2907},[2744,2763,2776,2786,2803,2818,2832,2849,2862,2874,2885,2894],{"slug":2745,"name":2745,"fn":2746,"description":2747,"org":2748,"tags":2749,"stars":2760,"repoUrl":2761,"updatedAt":2762},"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},[2750,2753,2756,2757],{"name":2751,"slug":2752,"type":16},"Agents","agents",{"name":2754,"slug":2755,"type":16},"SDK","sdk",{"name":9,"slug":8,"type":16},{"name":2758,"slug":2759,"type":16},"Workflow Automation","workflow-automation",14401,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Ftrigger.dev","2026-07-02T17:12:52.307135",{"slug":2764,"name":2764,"fn":2765,"description":2766,"org":2767,"tags":2768,"stars":2760,"repoUrl":2761,"updatedAt":2775},"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},[2769,2772,2773,2774],{"name":2770,"slug":2771,"type":16},"Backend","backend",{"name":2754,"slug":2755,"type":16},{"name":9,"slug":8,"type":16},{"name":2758,"slug":2759,"type":16},"2026-07-02T17:12:48.396964",{"slug":2777,"name":2777,"fn":2778,"description":2779,"org":2780,"tags":2781,"stars":2760,"repoUrl":2761,"updatedAt":2785},"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},[2782,2783,2784],{"name":2751,"slug":2752,"type":16},{"name":9,"slug":8,"type":16},{"name":2758,"slug":2759,"type":16},"2026-07-02T17:12:51.03018",{"slug":2787,"name":2787,"fn":2788,"description":2789,"org":2790,"tags":2791,"stars":2760,"repoUrl":2761,"updatedAt":2802},"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},[2792,2795,2798,2801],{"name":2793,"slug":2794,"type":16},"Frontend","frontend",{"name":2796,"slug":2797,"type":16},"React","react",{"name":2799,"slug":2800,"type":16},"Real-time","real-time",{"name":9,"slug":8,"type":16},"2026-07-02T17:12:49.717706",{"slug":2804,"name":2804,"fn":2805,"description":2806,"org":2807,"tags":2808,"stars":2815,"repoUrl":2816,"updatedAt":2817},"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},[2809,2810,2813,2814],{"name":2751,"slug":2752,"type":16},{"name":2811,"slug":2812,"type":16},"Multi-Agent","multi-agent",{"name":9,"slug":8,"type":16},{"name":2758,"slug":2759,"type":16},30,"https:\u002F\u002Fgithub.com\u002Ftriggerdotdev\u002Fskills","2026-04-06T18:54:46.023553",{"slug":2819,"name":2819,"fn":2820,"description":2821,"org":2822,"tags":2823,"stars":2815,"repoUrl":2816,"updatedAt":2831},"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},[2824,2827,2830],{"name":2825,"slug":2826,"type":16},"Configuration","configuration",{"name":2828,"slug":2829,"type":16},"Deployment","deployment",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:44.764258",{"slug":2833,"name":2833,"fn":2834,"description":2835,"org":2836,"tags":2837,"stars":2815,"repoUrl":2816,"updatedAt":2848},"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},[2838,2841,2844,2847],{"name":2839,"slug":2840,"type":16},"Analytics","analytics",{"name":2842,"slug":2843,"type":16},"Cost Optimization","cost-optimization",{"name":2845,"slug":2846,"type":16},"Operations","operations",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:48.555552",{"slug":2850,"name":2850,"fn":2851,"description":2852,"org":2853,"tags":2854,"stars":2815,"repoUrl":2816,"updatedAt":2861},"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},[2855,2856,2859,2860],{"name":2793,"slug":2794,"type":16},{"name":2857,"slug":2858,"type":16},"Observability","observability",{"name":2799,"slug":2800,"type":16},{"name":9,"slug":8,"type":16},"2026-04-06T18:54:47.293822",{"slug":2863,"name":2863,"fn":2864,"description":2865,"org":2866,"tags":2867,"stars":2815,"repoUrl":2816,"updatedAt":2873},"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},[2868,2869,2872],{"name":2825,"slug":2826,"type":16},{"name":2870,"slug":2871,"type":16},"Local Development","local-development",{"name":9,"slug":8,"type":16},"2026-04-06T18:54:42.280816",{"slug":2875,"name":2875,"fn":2876,"description":2877,"org":2878,"tags":2879,"stars":2815,"repoUrl":2816,"updatedAt":2884},"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},[2880,2881,2882,2883],{"name":2751,"slug":2752,"type":16},{"name":2770,"slug":2771,"type":16},{"name":9,"slug":8,"type":16},{"name":2758,"slug":2759,"type":16},"2026-04-06T18:54:43.514369",{"slug":2886,"name":2886,"fn":2887,"description":2888,"org":2889,"tags":2890,"stars":23,"repoUrl":24,"updatedAt":2893},"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},[2891,2892],{"name":18,"slug":19,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:42.723559",{"slug":2895,"name":2895,"fn":2896,"description":2897,"org":2898,"tags":2899,"stars":23,"repoUrl":24,"updatedAt":2906},"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},[2900,2901,2904,2905],{"name":18,"slug":19,"type":16},{"name":2902,"slug":2903,"type":16},"Caching","caching",{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:45.194583",26,{"items":2909,"total":1206},[2910,2915,2922,2928,2940,2953,2965],{"slug":2886,"name":2886,"fn":2887,"description":2888,"org":2911,"tags":2912,"stars":23,"repoUrl":24,"updatedAt":2893},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[2913,2914],{"name":18,"slug":19,"type":16},{"name":14,"slug":15,"type":16},{"slug":2895,"name":2895,"fn":2896,"description":2897,"org":2916,"tags":2917,"stars":23,"repoUrl":24,"updatedAt":2906},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[2918,2919,2920,2921],{"name":18,"slug":19,"type":16},{"name":2902,"slug":2903,"type":16},{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},{"slug":4,"name":4,"fn":5,"description":6,"org":2923,"tags":2924,"stars":23,"repoUrl":24,"updatedAt":25},{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[2925,2926,2927],{"name":18,"slug":19,"type":16},{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},{"slug":2929,"name":2929,"fn":2930,"description":2931,"org":2932,"tags":2933,"stars":23,"repoUrl":24,"updatedAt":2939},"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},[2934,2935,2938],{"name":18,"slug":19,"type":16},{"name":2936,"slug":2937,"type":16},"Debugging","debugging",{"name":21,"slug":22,"type":16},"2026-06-17T08:40:37.803541",{"slug":2941,"name":2941,"fn":2942,"description":2943,"org":2944,"tags":2945,"stars":23,"repoUrl":24,"updatedAt":2952},"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},[2946,2947,2950,2951],{"name":18,"slug":19,"type":16},{"name":2948,"slug":2949,"type":16},"Database","database",{"name":21,"slug":22,"type":16},{"name":14,"slug":15,"type":16},"2026-06-17T08:40:46.442182",{"slug":2954,"name":2954,"fn":2955,"description":2956,"org":2957,"tags":2958,"stars":23,"repoUrl":24,"updatedAt":2964},"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},[2959,2960,2963],{"name":18,"slug":19,"type":16},{"name":2961,"slug":2962,"type":16},"Data Modeling","data-modeling",{"name":2948,"slug":2949,"type":16},"2026-06-17T08:40:53.835868",{"slug":2966,"name":2966,"fn":2967,"description":2968,"org":2969,"tags":2970,"stars":23,"repoUrl":24,"updatedAt":2976},"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},[2971,2974,2975],{"name":2972,"slug":2973,"type":16},"API Development","api-development",{"name":18,"slug":19,"type":16},{"name":21,"slug":22,"type":16},"2026-06-17T08:40:47.666795"]