Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš– RideFlux

A Production-Inspired Backend Engineering Project for Ride-Hailing Systems

Built with Spring Boot β€’ Apache Kafka β€’ Redis β€’ MySQL β€’ Docker β€’ WebSockets


Overview

RideFlux is a production-inspired backend system that explores how modern ride-hailing platforms solve complex distributed systems and scalability challenges.

Rather than focusing on CRUD operations, RideFlux emphasizes backend engineering concepts such as reliable event processing, asynchronous communication, fault-tolerant ride dispatching, real-time updates, intelligent caching, and scalable driver discovery.

The project combines synchronous REST APIs with asynchronous event-driven communication to simulate the architecture of large-scale ride-hailing platforms.


Why RideFlux?

Building a ride-booking platform is significantly more complex than exposing REST endpoints.

A production backend must be able to:

  • Prevent duplicate ride creation
  • Find nearby drivers with low latency
  • Recover automatically when drivers reject or ignore requests
  • Deliver events reliably without losing data
  • Process thousands of location updates efficiently
  • Notify clients in real time
  • Scale independently across multiple backend components
  • Remain resilient even during partial failures

RideFlux was built to explore how these engineering problems can be solved using modern backend architecture.


Backend Engineering Highlights

RideFlux focuses on solving real-world backend engineering challenges commonly found in large-scale ride-hailing platforms.

πŸš€ Event Driven Architecture (EDA)

Implements an asynchronous Event Driven Architecture using Apache Kafka's Publish-Subscribe model, enabling loose coupling between business components such as dispatch, notifications, auditing, analytics, and retry processing.


πŸ“¨ Apache Kafka Integration

Apache Kafka serves as the asynchronous messaging backbone of RideFlux, enabling reliable communication between independent backend modules.

Implemented Kafka Patterns

  • Transactional Outbox Pattern – Ensures database updates and Kafka event publication remain consistent by persisting events in an Outbox table before publishing.
  • Dead Letter Topic (DLT) – Failed events are redirected to dedicated dead-letter topics after retry attempts, preventing message loss and simplifying failure analysis.
  • Retry Processing – Automatically retries transient failures such as driver timeouts or temporary processing errors before routing events to the DLT.

Key Benefits

  • Reliable event delivery
  • Asynchronous processing
  • Loose coupling between components
  • Improved scalability and fault tolerance
  • Independent event consumers for dispatch, notifications, analytics, and auditing

πŸ“¦ Reliable Event Delivery

Implements the Transactional Outbox Pattern to guarantee reliable event publication between the database and Kafka, preventing event loss and maintaining consistency even during application failures.


πŸ” Fault-Tolerant Dispatch Engine

Built a resilient ride dispatch engine featuring:

  • Automatic retry mechanism
  • Driver timeout handling
  • Progressive search radius expansion
  • Driver reassignment
  • Asynchronous dispatch workflow

This improves ride assignment success while avoiding unnecessary driver notifications.


πŸ›‘οΈ Idempotent APIs

Implements request idempotency to ensure duplicate client requests never create duplicate rides, making APIs safe under retries and unstable network conditions.


⚑ High-Performance Driver Discovery

Uses Redis GEO for efficient geospatial indexing, enabling millisecond-level nearby driver discovery without expensive database queries.


πŸ’Ύ Intelligent Redis Caching

Leverages Redis for caching frequently accessed data including:

  • Driver locations
  • Online drivers
  • Active rides
  • Fare estimates
  • Tracking information

This significantly reduces database load and improves response latency.


πŸ“‘ Real-Time Communication

Uses WebSockets (STOMP) to push live updates without polling.

Supports real-time events such as:

  • Driver assignment
  • Ride status updates
  • Driver requests
  • Driver location tracking
  • Live trip sharing

πŸ“¨ Asynchronous Processing

Long-running operations are processed asynchronously through Kafka consumers, improving responsiveness and enabling better scalability under concurrent request loads.


πŸ” Secure Authentication & Authorization

Secured using Spring Security with JWT-based authentication and Role-Based Access Control (RBAC) supporting Rider, Driver, and Admin roles.


πŸ—οΈ Clean Architecture & Design Patterns

Applies enterprise software design principles including:

  • Strategy Pattern
  • Factory Pattern
  • Adapter Pattern
  • Facade Pattern
  • Repository Pattern
  • Observer Pattern (Spring Events)

to keep the codebase modular, maintainable, and extensible.


🐳 Production-Inspired Deployment

The complete development environment is containerized using Docker Compose, including:

  • Spring Boot Application
  • MySQL
  • Redis
  • Apache Kafka

allowing the project to be started locally with a single command.


Features

Component Responsibility
Ride Management Ride booking, ride lifecycle management, cancellation, completion, and ride history.
Dispatch Engine Nearby driver discovery, ride assignment, timeout handling, automatic retry mechanism, and progressive radius expansion.
Tracking Service Real-time driver location updates, live ride tracking, route sharing, ETA calculation, and Redis GEO integration.
Event Processing Kafka producers & consumers, Transactional Outbox, event publication, retry processing, and Dead Letter Topic (DLT) handling.
Notification Layer Real-time WebSocket notifications for ride status updates, driver requests, driver locations, and live trip sharing.

Reliability Mechanisms

RideFlux incorporates several production-inspired reliability mechanisms that improve consistency, fault tolerance, and scalability under high request volumes.

Engineering Problem Solution
Duplicate Ride Requests Idempotency Layer
Lost Events Transactional Outbox Pattern
Failed Event Processing Dead Letter Topic (DLT)
Driver Doesn't Respond Automatic Retry Mechanism
No Nearby Driver Progressive Radius Expansion
Slow Database Queries Redis Caching
Driver Discovery Redis GEO Indexing
Real-Time Communication WebSockets
Loose Coupling Event Driven Architecture
Asynchronous Processing Apache Kafka

These mechanisms work together to build a backend capable of handling failures without affecting the user experience.


Technology Stack

Category Technologies
Backend Java 21, Spring Boot, Spring MVC, Spring Security, Spring Data JPA, Hibernate
Database & Caching MySQL, Redis (Caching & GEO)
Messaging Apache Kafka
Real-Time Communication WebSockets (STOMP)
Authentication & Authorization JWT, Spring Security, Role-Based Access Control (RBAC)
Build & Dependency Management Maven
Containerization Docker, Docker Compose

Running Locally

RideFlux is fully containerized using Docker Compose, making local setup straightforward.

Prerequisites

Install the following tools before running the project:

  • Java 21
  • Maven
  • Docker
  • Docker Compose
  • Git

Clone the Repository

git clone https://github.com/<your-username>/RideFlux.git

cd RideFlux

Build the Project

mvn clean package

Start the Complete Environment

docker compose up --build

This command starts:

  • RideFlux Application
  • MySQL
  • Redis
  • Apache Kafka

Load Sample Data

After all containers have started successfully, load the provided sample dataset.

Open the MySQL container:

docker exec -it <mysql-container-name> mysql -u root -p

Enter your MySQL password.

Select the database:

USE RideFlux;

Execute the SQL script available in:

src/main/resources/data.sql

or directly from GitHub:

https://github.com/<your-username>/RideFlux/blob/main/src/main/resources/data.sql

The sample dataset contains:

  • Demo Users
  • Riders
  • Drivers
  • Vehicles
  • Driver Locations
  • Vehicle Categories
  • Ride Types
  • Pricing Rules
  • Test Data for Dispatch Engine

Loading this dataset allows immediate testing of ride booking, dispatch, tracking and WebSocket functionality.


Engineering Decisions

Several architectural decisions were made to simulate production backend systems rather than simple CRUD applications.


Why Event Driven Architecture?

Ride dispatch, analytics, notifications and auditing should not block REST requests.

Using asynchronous events allows these components to evolve independently while improving scalability.


Why Apache Kafka?

Kafka provides:

  • Reliable event delivery
  • Asynchronous communication
  • Loose coupling
  • Independent consumers
  • High throughput

This makes it suitable for backend systems processing large numbers of business events.


Why Transactional Outbox?

Publishing events directly after committing a database transaction introduces the risk of losing events if the application crashes.

The Transactional Outbox Pattern guarantees that committed business operations are eventually published to Kafka.


Why Redis GEO?

Searching nearby drivers using SQL queries becomes inefficient as the number of drivers increases.

Redis GEO enables efficient geospatial searches with low latency, making it ideal for driver discovery.


Why WebSockets?

Polling REST endpoints for ride updates increases server load and introduces unnecessary latency.

WebSockets provide instant communication between the backend and connected clients.


Why Redis Caching?

Ride-hailing applications continuously access rapidly changing information such as:

  • Driver locations
  • Active rides
  • Online drivers
  • Fare estimates

Caching this data significantly reduces database load and improves response times.


Why Idempotency?

Network instability often causes mobile applications to resend requests.

Without idempotency, duplicate requests may create duplicate rides.

RideFlux guarantees that identical requests are processed exactly once.


Scalability Considerations

RideFlux has been designed with scalability in mind.

Current architecture enables:

  • Asynchronous event processing
  • Independent Kafka consumers
  • Fast Redis-based lookups
  • Cached frequently accessed data
  • Real-time communication
  • Decoupled backend components

Although currently implemented as a modular monolith, the architecture intentionally follows patterns commonly adopted by distributed microservice systems.


Future Improvements

  • Payment Gateway Integration
  • Api Gateway
  • Kubernetes Deployment
  • Convert to Microservices Architecture

Learning Outcomes

This project was built to explore backend engineering principles beyond standard CRUD applications.

Key learning areas include:

  • Designing scalable backend architectures
  • Building fault-tolerant systems
  • Reliable event processing
  • Distributed messaging using Kafka
  • High-performance caching with Redis
  • Geospatial search using Redis GEO
  • Real-time communication using WebSockets
  • Secure authentication and authorization
  • Enterprise software design patterns
  • Docker-based local deployment

Contributing

Contributions, suggestions and improvements are welcome.

If you discover bugs or have ideas for new features, feel free to open an issue or submit a pull request.


License

This project was built for educational purposes and backend engineering practice.

Feel free to fork, learn from, and extend the project.

If you find the project useful, consider giving it a ⭐ on GitHub.


RideFlux

Exploring scalable backend architecture through modern distributed systems patterns.

Built with ❀️ using Spring Boot, Apache Kafka, Redis and Docker.

About

Scalable ride-hailing backend demonstrating Event-Driven Architecture, Kafka, Redis GEO, Transactional Outbox, WebSockets, JWT authentication, idempotent APIs, and intelligent ride dispatch with retry and radius expansion.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages