distributed-counter

Design distributed counters using sharding, CRDTs, and HyperLogLog.

Updated Jun 5, 2026
One-click install
npx skills add https://github.com/hung-phan/system-skills --skill distributed-counter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: distributed-counter
Source: https://github.com/hung-phan/system-skills/tree/main/skills/system-review/references/interview-templates/distributed-counter
Command: npx skills add https://github.com/hung-phan/system-skills --skill distributed-counter

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps you design a distributed counter that can handle millions of writes per second without lost updates, hot-shard p99 spikes, or 'view count keeps decrementing' bugs.

Core Features & Use Cases

  • Sharded Counters: Distribute the write load across multiple physical sub-counters.
  • CRDTs: Use Conflict-free Replicated Data Types for distributed counting.
  • HyperLogLog: Estimate unique counts with constant memory usage.
  • Use Case: Ideal for view counts, like counts, ad impressions, vote tallies, rate-limit counters, and unique-visitor metrics where you can tolerate some error.

Quick Start

Generate a distributed counter with the 'distributed-counter' skill and configure the required parameters.

Frequently Asked Questions about distributed-counter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a distributed counter for high write rates without losing updates?

Sharding distributes the write load across multiple physical sub-counters, while Conflict-free Replicated Data Types (CRDTs) ensure data integrity without lost updates. This combination prevents hot-shard p99 spikes during high write contention.

What is the best way to estimate unique counts with constant memory in a distributed system?

HyperLogLog estimates unique counts with constant memory usage by providing approximate counting for unique-visitor metrics. It trades exact accuracy for high scalability when you can tolerate some error in distributed counting.

When should I use CRDTs instead of simple sharding for distributed counting?

Use CRDTs instead of simple sharding when you need conflict-free updates across distributed nodes without coordination. CRDTs ensure data integrity automatically, whereas simple sharding alone cannot prevent lost updates during network partitions.

How do I stop hot-shard p99 spikes when tracking view counts and ad impressions?

Implement sharded counters to distribute the write load across multiple physical sub-counters. This approach handles millions of writes per second for view counts and ad impressions without creating hot-shard p99 bottlenecks.

Does a distributed counter approach work for rate-limit counters and vote tallies?

Yes, the distributed counter approach works for rate-limit counters and vote tallies by using sharding and CRDTs to handle high write contention. It ensures accurate counting for vote tallies and reliable throttling for rate-limit counters.

What are the limitations of using HyperLogLog for distributed counting?

The main limitation of HyperLogLog for distributed counting is that it provides approximate counts rather than exact numbers. You should not use it when precise data integrity is required, as it trades accuracy for constant memory usage.