A complete microservices-based food delivery platform with real-time tracking, order management, and delivery coordination.
- API Gateway: Request routing, rate limiting, and shard-aware request forwarding
- Auth Service: User, restaurant, and delivery partner authentication with JWT
- Order Service: Order creation and lifecycle management with event publishing
- Restaurant Service: Restaurant metadata and menu management
- Delivery Service: Delivery partner assignment and order fulfillment
- Tracking Service: Real-time location tracking via WebSockets
- PostgreSQL (3 Shards): Application-level sharding by region/city
- Shard A: US-West, Canada
- Shard B: US-East, US-Central
- Shard C: US-South, Mexico
- MongoDB: Restaurant metadata, menus, and catalogs
- Redis: Rider location caching and pub/sub messaging
- RabbitMQ: Asynchronous event streaming between services
- Docker: Containerized deployment for all services
- Nginx: Load balancing and reverse proxy
- Socket.IO: Real-time WebSocket communication
- Prisma ORM: Database abstraction with multiple shard configurations
- Runtime: Node.js 18+
- Language: TypeScript
- APIs: Express.js / Fastify
- WebSockets: Socket.IO
- Databases: PostgreSQL (sharded), MongoDB
- Cache/Pub-Sub: Redis
- Message Queue: RabbitMQ
- ORM: Prisma
- Frontend: React 18, Vite, Tailwind CSS
- Containerization: Docker, Docker Compose
instant-eats/
├── services/
│ ├── api-gateway/ # Request routing & sharding awareness
│ ├── auth-service/ # Authentication & authorization
│ ├── order-service/ # Order management & RabbitMQ publishing
│ ├── restaurant-service/ # Restaurant metadata & MongoDB
│ ├── delivery-service/ # Delivery management & RabbitMQ consuming
│ └── tracking-service/ # Real-time tracking with Socket.IO
├── shared/ # Shared types, interfaces, utilities
│ └── sharding/ # Sharding configuration & routing logic
├── frontend/ # React + Vite + Tailwind scaffold
├── docker-compose.yml # Multi-container orchestration
├── nginx.conf # Load balancer configuration
├── tsconfig.base.json # Base TypeScript configuration
├── .env.example # Environment variables template
└── README.md # This file
The system implements application-level sharding with three PostgreSQL instances:
Defines shard endpoints and their associated regions:
- Shard A: US-West, Canada
- Shard B: US-East, US-Central
- Shard C: US-South, Mexico
Routes requests to appropriate shard based on:
- User's city or region
- Order location
- Delivery region
Each service using PostgreSQL imports the shard routing logic and maintains separate Prisma configurations for each shard.
- Docker & Docker Compose
- Node.js 18+
- npm or yarn
- Clone the repository:
git clone <repo-url>
cd instant-eats- Copy environment file:
cp .env.example .env- Start all services:
docker-compose up -dServices will be available at:
- API Gateway:
http://localhost:3000 - Nginx Load Balancer:
http://localhost:80 - RabbitMQ Management:
http://localhost:15672(guest:guest)
For local development without Docker:
# Install dependencies for each service
cd services/api-gateway && npm install
cd ../auth-service && npm install
# ... repeat for other services
# Run each service in separate terminal
npm run devRun migrations for each shard:
# Shard A
cd services/auth-service
DATABASE_URL=$POSTGRES_SHARD_A_URL npx prisma migrate dev --schema=prisma/shardA/schema.prisma
# Shard B
DATABASE_URL=$POSTGRES_SHARD_B_URL npx prisma migrate dev --schema=prisma/shardB/schema.prisma
# Shard C
DATABASE_URL=$POSTGRES_SHARD_C_URL npx prisma migrate dev --schema=prisma/shardC/schema.prisma- Customer creates order via API Gateway
- Order Service writes to appropriate shard based on city
- Order Service publishes
order.createdto RabbitMQ - Delivery Service consumes event and assigns delivery partner
- Delivery Service publishes
order.assignedto RabbitMQ - Tracking Service updates customer websocket with delivery info
POST /auth/register- Register user/restaurant/delivery partnerPOST /auth/login- Login and get JWTPOST /auth/refresh- Refresh JWT tokenPOST /auth/logout- Logout
POST /orders- Create new orderGET /orders/:id- Get order detailsGET /orders- List user's ordersPATCH /orders/:id/status- Update order status
GET /restaurants- List restaurantsGET /restaurants/:id- Get restaurant detailsGET /restaurants/:id/menu- Get restaurant menuPOST /restaurants- Create new restaurant
GET /delivery/assignments- Get delivery assignmentsPATCH /delivery/:id/location- Update rider locationPOST /delivery/:id/accept- Accept delivery
- WebSocket:
/tracking?orderId=<id>- Subscribe to order tracking updates
curl http://localhost/healthdocker-compose logs -f <service-name>Navigate to http://localhost:15672 with credentials guest:guest
All services read from .env file. Key configurations:
NODE_ENV: development | production- Shard URLs: Postgres connection strings for each shard
JWT_SECRET: Secret key for JWT signingREDIS_URL: Redis connection stringRABBITMQ_URL: RabbitMQ connection string
- Use strong JWT secret
- Enable HTTPS (update nginx.conf)
- Configure proper CORS policies
- Set up database backups for all shards
- Implement comprehensive logging and monitoring
- Configure auto-scaling policies
- Set up CI/CD pipeline
- Implement API request authentication at gateway
- Add comprehensive error handling
User requests cancellation ↓ GET /orders/:id/cancellation-info (check eligibility) ↓ DELETE /orders/:id/cancel (process cancellation) ↓ Calculate refund based on time elapsed + status ↓ Call Payment Service → Process refund ↓ Update order status to CANCELLED ↓ Call Notification Service → Notify all parties ↓ Log cancellation in OrderCancellation table ↓ Return refund confirmation to customer
Currently four different forms of communications occur : 1)HTTP/HTTPS Synchronous Requests by the frontend clients to a set of services like Hotels,Ordering,Login etc.. 2)RabbitQ Event Driven Architecture for the order.events to maintain and trigger the functions of each service based on the phase of the order in its lifecycle 3)Socket IO room is created between the user and the Updates from the Redis Cache uploaded by the Delivery Service after specific time intervals in REAL TIME 4)Direct Inter-Service HTTP Calls where the order service makes direct axios calls to Notification and the payment service
NOW WE UPDATE THESE TO GRPC protocol forms
MIT