---
title: "Challenge #2: Unique ID Generation"
---

# Challenge #2: Unique ID Generation

In this challenge, you’ll need to implement a globally-unique ID generation system that runs against Maelstrom’s [`unique-ids`](https://github.com/jepsen-io/maelstrom/blob/main/doc/workloads.md#workload-unique-ids) workload. Your service should be totally available, meaning that it can continue to operate even in the face of network partitions.

## Specification

### RPC: `generate`

Your node will receive a request message body that looks like this:

```
{
  "type": "generate"
}
```

and it will need to return a `"generate_ok"` message with a unique ID:

```
{
  "type": "generate_ok",
  "id": 123
}
```

The `msg_id` and `in_reply_to` fields have been removed for clarity but they exist as described in the [previous challenge](https://fly.io/dist-sys/1/). IDs may be of any type–strings, booleans, integers, floats, arrays, etc.

## Evaluation

Build your node binary as `maelstrom-unique-ids` and run it against Maelstrom with the following command:

```
./maelstrom test -w unique-ids --bin ~/go/bin/maelstrom-unique-ids --time-limit 30 --rate 1000 --node-count 3 --availability total --nemesis partition
```

This will run a 3-node cluster for 30 seconds and request new IDs at the rate of 1000 requests per second. It checks for total availability and will induce network partitions during the test. It will also verify that all IDs are unique.

If you see an *“Everything looks good”* message, congrats! Continue on to the [Broadcast challenge](https://fly.io/dist-sys/3a). If you’re having trouble, ask for help on the [Fly.io Community forum](https://community.fly.io/).

1. **Echo**
   Get the hang of working with Maelstrom in Go by creating a node which is a binary that receives JSON messages
   
   [Read More About Echo](https://fly.io/dist-sys/1)
2. **Unique ID Generation**
   Implement a globally-unique ID generation system that runs against Maelstrom's unique-ids workload
   
   [Read More About Unique ID Generation](https://fly.io/dist-sys/2)
3. **Broadcast**
   Implement a broadcast system that gossips messages between all nodes in the cluster. Gossiping is a common way
   
   [Read More About Broadcast](https://fly.io/dist-sys/3a)
4. **Grow-Only Counter**
   Implement a stateless, grow-only counter which will run against Maelstrom's g-counter workload. This
   
   [Read More About Grow-Only Counter](https://fly.io/dist-sys/4)
5. **Kafka-Style Log**
   Implement a replicated log service similar to Kafka. Replicated logs are often used as a message bus or
   
   [Read More About Kafka-Style Log](https://fly.io/dist-sys/5a)
6. **Totally-Available Transactions**
   Implement a key/value store which implements transactions. These transactions contain micro-operations
   
   [Read More About Totally-Available Transactions](https://fly.io/dist-sys/6a)
