/devops-ofds-java

DevOps Project - Online Food Delivery System

Primary LanguageJavaMIT LicenseMIT

πŸ• devops-ofds-java

DevOps Project – Online Food Delivery System


🧭 Overview

The Online Food Delivery System (OFDS) is a microservices-based application demonstrating DevOps best practices. It showcases:

  • Inter-service communication
  • API Gateway routing
  • Observability with tracing, logging, metrics, and profiling

Built using Java Spring Boot, Spring Cloud Gateway, Docker, and Docker Compose.


πŸ—οΈ Architecture

πŸ”§ Components

  1. API Gateway (Spring Cloud Gateway)

    • Entry point for all requests
    • Routes traffic to backend services
    • Supports load balancing and centralized routing
  2. Order Service

    • Manages customer orders
    • Stores customer name, dish, status, and restaurant ID
    • Retrieves restaurant details from the Restaurant Service
  3. Restaurant Service

    • Manages restaurant data: name, location, cuisine type
    • Returns details for a given restaurant ID
  4. Delivery Service

    • Manages deliveries with order ID, driver name, and status
    • Retrieves order details from the Order Service
  5. PostgreSQL

    • Dedicated database per service
    • Uses Docker volumes for persistence

πŸ” Request Flow

  1. Client sends request to API Gateway

  2. Gateway routes based on URI:

    • /api/orders/** β†’ Order Service
    • /api/restaurants/** β†’ Restaurant Service
    • /api/deliveries/** β†’ Delivery Service
  3. Order Service may query Restaurant Service

  4. Delivery Service may query Order Service

  5. All inter-service calls go through the Gateway


πŸ“‘ API Endpoints

🧾 Order Service

# Create Order
curl -X POST http://localhost:8080/api/orders \
  -H "Content-Type: application/json" \
  -d '{"customerName": "John", "dishName": "Pizza", "status": "Pending", "restaurantId": 1}'

# List Orders
curl http://localhost:8080/api/orders

# Get Order by ID
curl http://localhost:8080/api/orders/1

# Update Order Status
curl -X PUT http://localhost:8080/api/orders/1/status \
  -H "Content-Type: application/json" \
  -d 'Delivered'

🍽️ Restaurant Service

# Create Restaurant
curl -X POST http://localhost:8080/api/restaurants \
  -H "Content-Type: application/json" \
  -d '{"name": "Pizza Palace", "location": "Cape Town", "cuisineType": "Italian"}'

# List Restaurants
curl http://localhost:8080/api/restaurants

# Get Restaurant by ID
curl http://localhost:8080/api/restaurants/1

🚚 Delivery Service

# Create Delivery
curl -X POST http://localhost:8080/api/deliveries \
  -H "Content-Type: application/json" \
  -d '{"orderId": 1, "driverName": "Jane", "status": "In Transit"}'

# List Deliveries
curl http://localhost:8080/api/deliveries

# Get Delivery by ID
curl http://localhost:8080/api/deliveries/1

▢️ Running the App

Start all services:

docker-compose up --build

Stop all services:

docker-compose down -v

πŸ“ Project Structure

services/
β”œβ”€β”€ gateway/
β”œβ”€β”€ order-service/
β”œβ”€β”€ restaurant-service/
└── delivery-service/

πŸ—ΊοΈ System Diagram

Architecture Overview:

Diagram

πŸ”„ Inter-Service Communication

From To Description
Order Service Restaurant Service Fetches restaurant info when returning an order
Delivery Service Order Service Fetches order info when returning a delivery
All API Gateway Routes requests internally and externally for consistency

Example:

http://gateway:8080/api/restaurants/{restaurantId}
http://gateway:8080/api/orders/{orderId}

πŸ” Observability

Run a complete observability stack to monitor logs, metrics, traces, and profiling:

πŸš€ Bootstrap Demo Traffic

./scripts/simulate.py

🧰 Stack Overview

Service Description
Grafana Visualization layer for metrics, logs, traces, and profiling. http://localhost:3000
Prometheus Scrapes and stores time-series metrics from services
Loki Centralized log aggregation
Promtail Ships container logs to Loki
Tempo Collects and stores distributed traces
Pyroscope Continuous performance profiling (CPU, memory)

πŸ“Š Dashboard Highlights

  • Real-time metrics (e.g., request count, order status)
  • Structured logging with search
  • Distributed traces via Tempo
  • CPU/memory flamegraphs with Pyroscope

πŸ” Viewing Traces

  • Go to Grafana > Explore
  • Select Tempo as data source
  • Filter by service name (e.g., api-gateway) and span name (GET delivery-service)
  • View traces and spans

Tempo Trace

πŸ“ˆ Dashboards

Under Dashboards > Demo Dashboard, you’ll find:

  • HTTP request breakdown
  • Orders created over time
  • Deliveries created and completed

Grafana Dashboard