Design a Distributed Counter (e.g., Video View Count & Likes).

Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer

System Design Scenario:

1. Problem: High concurrency write contention on a single database row.

2. Solution: Write-back buffer or "Sharded Counters".

* Sharded Counters: Instead of one row per video, have N rows. Randomly pick one row to increment. Read sum of all rows.

* In-memory aggregation (Redis) -> Periodic flush to Persistent DB.