07 / 10

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

Difficulty: 8/10
worker coordination, persistence, fault tolerance

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

Scenario Questions

0-2 years experience

  1. 1Suppose you need to process image‑resizing jobs in a Go service. How would you set up a simple in‑memory task queue that workers can pull from without using any external libraries?
  2. 2If a worker crashes while processing a job, what happens to the task in your in‑memory queue, and how could you detect and retry it?
  3. 3How would you ensure that multiple goroutine workers don’t pick the same job from the queue?

2-5 years experience

  1. 1You’re adding a background email‑sending feature to an existing Go microservice. Describe how you would design a distributed task queue that works across multiple instances, handling persistence and retries, without pulling in a library like NSQ.
  2. 2During load testing you notice tasks sometimes get lost when a node restarts. What could be causing this, and how would you modify your queue implementation to fix it?
  3. 3Explain the trade‑offs between using a central Redis list versus a peer‑to‑peer gossip protocol for coordinating workers in your Go queue.

5-8 years experience

  1. 1Design a fault‑tolerant distributed task queue in Go that must handle millions of tasks per hour, guarantee at‑least‑once delivery, and survive network partitions. What components would you build, and how would they interact?
  2. 2How would you implement back‑pressure and rate limiting in your Go task queue to prevent overwhelming downstream services while still maintaining high throughput?
  3. 3If you need to add priority handling to your queue, what changes would you make to the data structures and worker logic, and what impact does it have on consistency and performance?

8+ years experience

  1. 1Your company is migrating from a legacy monolith that uses a custom task queue to a cloud‑native microservice architecture in Go. How would you plan the migration to ensure zero downtime and data integrity, and what long‑term design patterns would you adopt for the new queue?
  2. 2Across several teams you need a shared distributed task queue that supports pluggable persistence backends and observability. What high‑level architecture would you propose, and how would you govern its evolution to avoid lock‑in?
  3. 3Discuss how you would incorporate tracing, metrics, and automated failure injection into the Go task queue to meet SLOs for latency and reliability across a global deployment.

Follow-up Questions

  • What would you monitor to detect a stuck worker?
  • How would you handle task ordering guarantees?
  • Can you describe how you’d test the failure‑recovery path?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.