top of page
Abstract Shapes

Career

Assignment: Building a Distributed Task Queue in Go

Scenario:

You are tasked with designing and implementing a distributed task queue system in Go. The system should allow users to enqueue tasks, process them concurrently across multiple worker nodes, and handle task retries, timeouts, and scheduling. The goal is to build a scalable and fault-tolerant system.

Requirements:

  • Step 1: Task Queue Implementation

  • Create a task queue where users can enqueue tasks with associated data and parameters. Implement worker nodes that can dequeue and process tasks concurrently. Ensure that tasks are processed reliably and can be retried if they fail.

  • Step 2: Distributed Task Processing

  • Implement a mechanism for distributing tasks across multiple worker nodes. Consider using Go's concurrency features and channels. Ensure that tasks can be processed concurrently and independently.

  • Step 3: Task Scheduling

  • Add a scheduling mechanism that allows tasks to be executed at specific times or intervals. Implement support for recurring tasks (e.g., cron-like scheduling).

  • Step 4: Task Timeout and Retries

  • Implement a timeout mechanism for tasks to prevent them from running indefinitely. Add support for automatic retries for failed tasks with exponential backoff.

  • Step 5: Monitoring and Metrics

  • Implement monitoring and metrics collection to track task processing times, success rates, and other relevant metrics. Use a library like Prometheus and Grafana for monitoring.

  •  Step 6: Scalability and Fault Tolerance

  • Ensure that the system can scale horizontally to handle a growing number of tasks and workers. Implement fault tolerance mechanisms to handle worker failures without data loss or duplication.

  • Step 7: API and Documentation

  • Create a simple API for users to enqueue tasks and view task status. Provide clear documentation on how to use the task queue, enqueue tasks, and retrieve task results.

  • Step 8: Testing and Benchmarking

  • Write unit tests and integration tests for the task queue and worker nodes. Conduct benchmarking to ensure the system can handle a high volume of tasks efficiently.

  • Step 9: Security

  • Implement security measures to protect against unauthorized access and data breaches. Secure sensitive data, such as task payloads and authentication tokens.

  • Step 10: Deployment and Orchestration

  • Prepare the application for deployment in a production environment. Provide deployment scripts and instructions for containerization (e.g., Docker) and orchestration (e.g., Kubernetes).

  • Step 11: Bonus (Optional)

  • Implement task prioritization. Add support for distributed locking to prevent concurrent execution of certain tasks. Implement task deduplication to avoid processing duplicate tasks. Integrate with message brokers like RabbitMQ or Kafka for enhanced scalability.

bottom of page