07 / 10

How would you implement a distributed task queue in Go without using an external framework?

Use Redis lists (BLPOP/RPUSH) or Kafka topics as the queue, goroutines as workers, and implement heartbeat/lease mechanisms for at-least-once delivery with a dead letter queue for failures.

Redis-based task queue
Production considerations
  1. 1

    At-least-once delivery: use RPOPLPUSH to move task to processing list, remove after success

  2. 2

    Idempotency: store processed task IDs in DB with a UNIQUE constraint to handle duplicate delivery

  3. 3

    asynq library: production-grade Redis-based queue with retries, scheduling, and dashboard

  4. 4

    Kafka with segmentio/kafka-go: durable, ordered, replayable — prefer over Redis for high-volume event streams

  5. 5

    Dead letter queue: capture failed tasks for manual inspection and replay after bug fixes