ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/identifier/tasks/task-2-2-5-multi-node
TASK

Implementation

Snowflake IDs derive their uniqueness from the machine_id component. With 10 bits, you can have 1024 unique machines generating IDs without any coordination.

Your task is to verify uniqueness and ordering across multiple nodes:

  1. Extract machine_id from Maelstrom node_id (e.g., "n3" -> machine_id 3)
  2. Generate IDs and verify they are unique within a node
  3. Implement a verify_ids handler that checks a list of IDs for uniqueness and ordering
Request:  {"type": "verify_ids", "msg_id": 1, "ids": [100, 200, 300, 200]}
Response: {"type": "verify_ids_ok", "in_reply_to": 1, "count": 4, "unique": 3, "is_sorted": false, "duplicates": [200]}

Sample Test Cases

Verify sorted unique IDsTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"verify_ids","msg_id":2,"ids":[10,20,30]}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "verify_ids_ok", "count": 3, "unique": 3, "is_sorted": true, "duplicates": [], "in_reply_to": 2, "msg_id": 1}}
Detect duplicates in ID listTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"verify_ids","msg_id":2,"ids":[10,20,10,30]}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "verify_ids_ok", "count": 4, "unique": 3, "is_sorted": false, "duplicates": [10], "in_reply_to": 2, "msg_id": 1}}

Hints

Hint 1
Each node uses its own machine_id extracted from the node_id
Hint 2
IDs from different nodes are unique because the machine_id bits differ
Hint 3
Within a single node, IDs must be monotonically increasing
Hint 4
Across nodes, IDs are only roughly sorted due to clock differences
Hint 5
Use the decompose function to verify machine_id extraction
OVERVIEW

Theoretical Hub

Concept overview coming soon

Key Concepts

multi-node coordinationuniqueness verificationmonotonicityID distribution
main.py
python
Multi-Node Snowflake ID Verification - The Identifier | Build Distributed Systems