This project implements a distributed task queue system using Go. It consists of multiple components working together to schedule, manage, and execute tasks efficiently.
Data flow diagram of Distributed Task Queue System
- Coordinator: The central component that manages task distribution and tracks execution status.
- Worker: Executes tasks assigned by the Coordinator.
- Scheduler: Handles task scheduling and insertion into the database.
- PostgreSQL Database: Stores task information and status.
- Task scheduling with specified execution times.
- Distributed task execution across multiple workers.
- Real-time task status updates.
- REST API for task submission, scheduling, and status checking.
- gRPC communication between components for efficient data transfer.
- Persistent storage of tasks and their statuses in PostgreSQL.
- Heartbeat mechanism to manage worker availability.
The system follows a distributed architecture:
- Clients interact with the Scheduler to schedule tasks and the Coordinator to submit immediate tasks or check status.
- The Coordinator manages a pool of Workers, distributing tasks and collecting status updates.
- Workers execute tasks and report back to the Coordinator.
- All task information is persisted in the PostgreSQL database.
- Go 1.21 or higher
- Docker and Docker Compose
- PostgreSQL
- Clone the repository:
git clone https://github.com/sagoresarker/task-queue.git
- Navigate to the project directory:
cd task-queue
- Build the project:
docker-compose build
-
Start the system:
docker-compose up
-
The system exposes the following services:
- Scheduler API:
http://localhost:8081
- Coordinator API:
http://localhost:8080
- Scheduler API:
-
To schedule a task:
curl -X POST http://localhost:8081/schedule -d '{"command":"your_task_command", "scheduled_at":"2023-04-01T15:04:05Z"}'
-
To check task status:
curl http://localhost:8081/status?task_id=your_task_id
- The project uses Protocol Buffers for defining the gRPC service interfaces.
- To modify the gRPC definitions, edit the
pkg/grpcapi/api.proto
file and regenerate the Go code using thepkg/grpcapi/build.sh
script.