How harshshah8/flight-booking-system works
Project Type and Purpose
• This is a microservice-based backend system for managing flight searches, inventory, bookings and payments. There is no user-facing frontend here—clients (e.g., web or mobile apps) consume REST APIs exposed by four Spring Boot services. Each service is packaged in Docker, orchestrated via Docker Compose, and backed by PostgreSQL and Redis.
File Structure
• Top-level modules:
• search-service (port 8081)
• inventory-service (port 8082)
• booking-service (port 8083)
• payment-service (port 8084)
• fbs-commons (shared library)
• infra (docker-compose.yml, init-db.sql)
• scripts (Python data-seeding)
• Each service follows a layered structure:
– config (Spring configs, Redis setup)
– controller (REST endpoints, health checks)
– service (business logic)
– repository/accessor (JPA or HTTP clients to other services)
– dto/entity/model/exception
• infra/docker-compose.yml defines container relationships, network and volume mounts.
README for Additional Insights
• Tech stack: Java 21, Spring Boot, REST, Docker, Redis, PostgreSQL, Python for seeding
• Service ports, startup order: first databases (Postgres, Redis), then seed data, then all Java services
• Clients interact directly with each service via its port
• Booking depends on Inventory and Payment; Inventory publishes seat-reservation events; Search listens to inventory events for cache updates.
Main Components & Their Interactions
a. API Consumer (Client)
– Initiates HTTP calls to Search, Inventory, Booking or Payment endpoints.
b. Search Service
– Receives /v1/search, queries Redis-cached graph or falls back to Inventory via REST.
– Subscribes to inventory change events (Redis Pub/Sub) to update in-memory graph cache.
c. Inventory Service
– Manages flights in PostgreSQL (flight_inventory_db).
– Exposes REST endpoints for flight data, seat reserve/release, admin operations.
– Publishes events (e.g., “seats reserved”) over Redis.
d. Booking Service
– Persists bookings in PostgreSQL (flight_booking_db).
– Calls InventoryServiceAccessor (REST) to reserve seats.
– Calls PaymentServiceAccessor (REST) to trigger payment.
e. Payment Service
– Processes /v1/payments/process, performs business rules, returns confirmation.
f. Shared Components
– PostgreSQL (single instance hosting two DBs: inventory + booking)
– Redis (cache + Pub/Sub)
– fbs-commons (shared exception types, utilities)
– data-seeding script (Python)
Key Architectural Patterns & Design Principles
• Microservices: each bounded context in its own deployable unit
• Layered/Spring-Boot conventions (Controller → Service → Repository)
• Event-driven cache synchronization (Inventory → Redis Pub/Sub → Search)
• Shared library for cross-cutting concerns (fbs-commons)
• Containerized deployment with Docker Compose
1. Sketch a top-level view: place Client at top.
3. Postgres and Redis beneath, connecting to services.
6. Service ports and database names.