This project is a personal solution for building a scalable Logistics Platform using Apache Kafka and other microservices.
graph TB
subgraph Client
CL[Client Applications]
end
subgraph Gateway
LB[Nginx Load Balancer]:::infra
AG["API Gateway"]:::gateway
WS["WebSocket Gateway"]:::gateway
end
subgraph Services
BS["Booking Service"]:::service
DS["Driver Service"]:::service
TS["Tracking Service"]:::service
PS["Pricing Service"]:::service
AS["Analytics Service"]:::service
ADS["Admin Service"]:::service
CS["Communication Service"]:::service
ASS["Assignment Service"]:::service
end
subgraph "Message Broker"
KB["Apache Kafka"]:::broker
end
subgraph "Background Processing"
AC["Analytics Consumer"]:::worker
BC["Booking Consumer"]:::worker
DC["Demand Consumer"]:::worker
LC["Location Consumer"]:::worker
CW["Celery Workers"]:::worker
end
subgraph "Data Layer"
PG[(PostgreSQL)]:::database
PGB[PgBouncer]:::database
RD[(Redis Cache)]:::cache
end
%% Client Layer Connections
CL --> LB
LB --> AG
LB --> WS
%% Gateway to Services
AG --> BS
AG --> DS
AG --> TS
AG --> PS
AG --> AS
AG --> ADS
WS --> CS
%% Service Interconnections
BS --> ASS
ASS --> DS
TS --> KB
DS --> KB
%% Message Broker to Consumers
KB --> AC
KB --> BC
KB --> DC
KB --> LC
%% Consumers to Services
AC --> AS
BC --> BS
LC --> TS
%% Services to Data Layer
BS --> PGB
DS --> PGB
TS --> PGB
PS --> PGB
AS --> PGB
ADS --> PGB
PGB --> PG
%% Cache Connections
BS --> RD
DS --> RD
TS --> RD
PS --> RD
%% Styles
classDef service fill:#90EE90,stroke:#333,stroke-width:2px
classDef gateway fill:#87CEEB,stroke:#333,stroke-width:2px
classDef broker fill:#FFA500,stroke:#333,stroke-width:2px
classDef database fill:#DDA0DD,stroke:#333,stroke-width:2px
classDef cache fill:#E6E6FA,stroke:#333,stroke-width:2px
classDef worker fill:#FFD700,stroke:#333,stroke-width:2px
classDef infra fill:#FF6B6B,stroke:#333,stroke-width:2px
%% Click Events
click LB "https://github.com/kshitijk4poor/logistics-platform/blob/main/nginx.conf"
click AG "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/main.py"
click WS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/routes/websockets.py"
click BS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/booking/booking_service.py"
click DS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/drivers/driver_service.py"
click TS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/tracking/tracking_service.py"
click PS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/pricing/pricing_service.py"
click AS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/analytics/analytics_service.py"
click ADS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/admin/admin_service.py"
click CS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/communication/notification.py"
click ASS "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/assignment/driver_assignment.py"
click KB "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/messaging/kafka_service.py"
click RD "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/caching/cache.py"
click AC "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/analytics/analytics_consumer.py"
click BC "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/booking/booking_consumer.py"
click DC "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/demand/demand_consumer.py"
click LC "https://github.com/kshitijk4poor/logistics-platform/blob/main/app/services/tracking/location_consumer.py"
click PGB "https://github.com/kshitijk4poor/logistics-platform/blob/main/pgbouncer.ini"
click PG "https://github.com/kshitijk4poor/logistics-platform/blob/main/db/database.py"
- 🚗 Real-time driver availability tracking
- 📊 Efficient data processing with Apache Kafka
- 🔄 Asynchronous task processing
- 🚀 Highly scalable microservices architecture
- 🧪 Comprehensive test suite
- 🌍 Real-time location tracking and geospatial indexing
- 💰 Dynamic pricing system
- 📅 Booking management with support for immediate and scheduled bookings
- 📈 Analytics service for data insights
- 🔔 Real-time notifications via WebSockets
This service is built with scalability in mind, utilizing a microservices architecture, Apache Kafka for efficient message processing, and FastAPI for high-performance API development.
- FastAPI Backend: Asynchronous Python web framework for high-performance API development.
- Apache Kafka: Distributed event streaming platform for handling high-volume data streams.
- PostgreSQL: Robust relational database for persistent storage.
- Redis: In-memory data store for caching and real-time data processing.
- Nginx: High-performance load balancer and reverse proxy.
- Docker & Docker Compose: Containerization for easy deployment and scaling.
- Celery: Distributed task queue for background job processing.
- Driver Availability Service: Handles real-time updates of driver availability
- Booking Service: Manages creation and processing of bookings
- Pricing Service: Calculates dynamic pricing based on various factors
- Driver Assignment Service: Efficiently assigns drivers to bookings
- Tracking Service: Manages real-time location updates from drivers
- Analytics Service: Processes and analyzes logistics data
- Communication Service: Manages WebSocket connections for real-time updates
- Admin Service: Provides endpoints for managing vehicles and other administrative tasks
For detailed information on each service and its workflows, please refer to the Technical Documentation.
- Microservices Architecture: Allows independent scaling of services.
- Asynchronous Processing: Utilizes FastAPI's asynchronous capabilities for non-blocking I/O operations.
- Message Streaming: Kafka for distributed event streaming and processing.
- Caching: Redis for fast data retrieval and reducing database load.
- Load Balancing: Nginx for distributing incoming traffic across multiple backend instances.
- Containerization: Docker for easy scaling of individual services.
- Geospatial Indexing: H3 for efficient location-based queries and operations.
- Task Scheduling: Celery for managing future bookings and related tasks.
-
Advanced Database Scaling:
- Implement database replication for improved read performance and fault tolerance.
- Set up geolocation-based sharding to optimize query performance for location-based operations.
- Explore multi-region database clusters for global scalability and reduced latency.
-
Enhanced Caching Strategy:
- Implement a distributed caching layer using Redis Cluster for improved cache performance and scalability.
- Develop intelligent cache invalidation mechanisms to ensure data consistency.
-
Serverless Computing Integration:
- Explore serverless options (e.g., AWS Lambda, Google Cloud Functions) for specific microservices to improve scalability and reduce operational costs.
-
Advanced Monitoring and Observability:
- Implement distributed tracing using tools like Jaeger or Zipkin for better visibility into microservices interactions.
- Set up advanced alerting and anomaly detection systems.
-
Edge Computing:
- Implement edge computing solutions for reduced latency in real-time location tracking and processing.
These future implementations will further enhance the scalability, performance, and feature set of the Driver Availability Service, ensuring its readiness for global-scale operations and emerging technologies.
- Clone the repository
- Set up environment variables (refer to
.env.example
) - Run
docker-compose up --build
to start all services - Access the API at
http://localhost:8000
Once the server is running, you can access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
We use pytest for unit and integration testing. Run tests with:
pytest
For more details on our testing strategy, including unit, integration, and end-to-end testing, please refer to the Technical Documentation.
This project implements various security measures, including:
- JWT-based authentication for API and WebSocket connections
- Rate limiting to prevent abuse
- Data encryption at rest and in transit
- Role-Based Access Control (RBAC)
For more information on security measures, please see the Technical Documentation.
The system is designed with performance and resilience in mind, implementing:
- Circuit breakers to prevent cascading failures
- Intelligent retry mechanisms for transient failures
- Comprehensive logging for all errors and exceptions
For more details, refer to the Technical Documentation.
The project uses:
- Docker for containerization
- Kubernetes for container orchestration and scaling
- Prometheus and Grafana for monitoring and alerting
For more information on deployment and DevOps practices, see the Technical Documentation.
While this is a personal project, I welcome any feedback or suggestions you might have.
This project implements advanced features such as real-time location tracking, geospatial indexing, and an advanced microservices architecture. For detailed information on these implementations, please refer to the Technical Documentation.