Index of every page on this site: llms.txt
All skills
proyecto26 avatar

/sharded-counters

@228d57d
Run it yourself

This skill should be used when the user needs a "sharded counter", "distributed counter", to "count likes / views at scale", handles a "high-write counter" or "hot counter contention", asks about "approximate counting", "real-time counts", or "HyperLogLog". It gives the recipe for absorbing write-heavy counting without a single hot row. Use it whenever one row/key takes concurrent increments faster than it can serialize them, even if the user doesn't say "sharded counter".

Use this Skill: https://skilld.dev/gh/proyecto26/system-design-skills/sharded-counters

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesprovidersaws.md

≈591 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Sharded counters — AWS

Only the contention/atomicity differences that change the recipe. Default to the generic recipe; this maps it to AWS services.

Service mapping

  • DynamoDB atomic counter — UpdateItem with an ADD/SET c = c + :n expression increments a number attribute atomically. The single-counter option.
  • DynamoDB + write sharding — append a random suffix to the partition key (pk = id#shard{rand(0..N-1)}), increment the sharded item, and sum the N items (a Query or N GetItems) on read. The striped-counter recipe — and the standard fix for a hot partition.
  • ElastiCache for Redis / Valkey — managed Redis for the fast path: INCR, HyperLogLog (PFADD/PFCOUNT), key sharding. Use when you want microsecond increments and built-in HLL.
  • Amazon Keyspaces (Cassandra) — managed counter columns for distributed-scale eventual counts (same non-idempotent caveat as generic).

When to pick which

DynamoDB atomic counter when the item is durable system-of-record and write rate fits one partition; DynamoDB write-sharding when a single partition key goes hot; ElastiCache Redis when the count is a fast/ephemeral tally with HLL needs.

Limits / things that bite (verify against current docs)

  • A DynamoDB partition has a hard write ceiling (historically ~1,000 WCU/s); hammering one key is a hot partition that throttles regardless of table capacity — write-sharding the key is the fix.
  • DynamoDB updates are atomic per item but the table is eventually consistent on reads unless you request a strongly-consistent read (which costs more and can't span the N sharded items as one transaction).
  • Reading a write-sharded total is N reads + a client-side sum; size N against the per-partition ceiling, not the average.
  • ElastiCache Multi-AZ failover takes seconds and can drop un-replicated increments.

Pitfalls

  • Leaving a viral counter on one partition key and blaming "DynamoDB throttling" — it's a hot partition; shard the key.
  • Assuming a single UpdateItem ADD scales infinitely — it's capped by the partition.
  • Forgetting the N-shard read can't be one strongly-consistent transaction — the summed total is eventually consistent.
  • Lock-in: DynamoDB key-sharding layout and Keyspaces counters don't port directly to other clouds.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts24d3 checks · Risk SAFE
  • Gen Agent Trust Hub24d

    This skill consists purely of architectural documentation and design patterns for distributed counters. It contains no executable code, network operations, or data-handling scripts, and presents no security risks.

  • Socket24d

    No alerts

  • Snyk24d

    Risk: LOW · No issues

Signed by skilld at 228d57d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 weeks ago.

Activeupdated 4 weeks ago

README badge

README badge for proyecto26/system-design-skills/sharded-counters