ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/store/tasks/task-8-3-5-contention-benchmark
TASK

Implementation

Benchmark a contended-key scenario: 100 clients all updating the same key simultaneously. Compare OCC vs MVCC in terms of abort rate and throughput.

Request:  {"type": "contention_benchmark", "msg_id": 1, "clients": 100, "key": "hot_key", "ops_per_client": 10, "strategies": ["occ", "mvcc_snapshot", "serializable"]}
Response: {"type": "contention_benchmark_ok", "in_reply_to": 1, "results": [
    {"strategy": "occ", "total_commits": 1000, "total_aborts": 4500, "abort_rate_pct": 81.8, "avg_retries": 4.5, "throughput_commits_sec": 200},
    {"strategy": "mvcc_snapshot", "total_commits": 1000, "total_aborts": 0, "abort_rate_pct": 0, "avg_retries": 0, "throughput_commits_sec": 5000},
    {"strategy": "serializable", "total_commits": 1000, "total_aborts": 900, "abort_rate_pct": 47.4, "avg_retries": 0.9, "throughput_commits_sec": 800}
]}

Sample Test Cases

Benchmark contended keyTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"contention_benchmark","msg_id":2,"clients":10,"key":"hot_key","ops_per_client":5,"strategies":["occ","mvcc_snapshot"]}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}

Hints

Hint 1
With 100 clients all updating the same key, OCC will have high abort rates
Hint 2
MVCC + snapshot isolation allows readers to proceed without blocking
Hint 3
Serializable isolation aborts conflicting writes
Hint 4
Measure abort rate, throughput (commits/sec), and average retries
Hint 5
The hot key scenario is worst-case for OCC
OVERVIEW

Theoretical Hub

Concept overview coming soon

Key Concepts

contentionabort ratethroughputOCC vs MVCChot key
main.py
python
Benchmark Contended Key Under OCC vs MVCC - The Store | Build Distributed Systems