TASK
Implementation
Use Maelstrom's built-in seq-kv service to store your counter value. This provides sequential consistency but introduces new challenges around availability during network partitions.
Sample Test Cases
KV-based counterTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"add","msg_id":2,"delta":10}}
{"src":"c2","dest":"n1","body":{"type":"read","msg_id":3}}
Expected Output
{"src":"n1","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}
{"src":"n1","dest":"c1","body":{"type":"add_ok","in_reply_to":2,"msg_id":1}}
{"src":"n1","dest":"c2","body":{"type":"read_ok","in_reply_to":3,"msg_id":2,"value":10}}
Hints
Hint 1▾
Use Maelstrom seq-kv service
Hint 2▾
Store counter in external KV
Hint 3▾
This still has issues under partitions
OVERVIEW
Theoretical Hub
Sequential Consistency
Sequential consistency guarantees that all operations appear to happen in some total order consistent with each process's local order. This is stronger than eventual consistency but weaker than linearizability.
Key Concepts
sequential consistencyexternal storagelinearizability
main.py
python
1
2
3
4
5
6
#!/usr/bin/env python3
import sys
import json
# TODO: Use seq-kv service for counter storage