Skip to content

freyderdev/worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Reactive Order Worker Service

πŸ“’ This project is now fully documented in English.
For the original version in Spanish, switch to the main branch.

A reactive event-driven microservice built with Spring Boot 3, Spring WebFlux, Apache Kafka, Redis, and MongoDB.

The service consumes order events from Kafka, enriches them with customer and product information obtained from external APIs, applies resilience patterns, and persists the resulting data in MongoDB.

This project demonstrates modern backend engineering practices including reactive programming, distributed caching, event-driven architecture, fault tolerance, and scalable asynchronous processing.


πŸ“‘ Table of Contents

  • Project Overview
  • Architecture Overview
  • Architecture Highlights
  • Key Features
  • Technology Stack
  • Project Structure
  • Setup
  • Run the Project
  • Sample Payload
  • Testing
  • Scalability and Optimization
  • Author

🌍 Project Overview

The application consumes order events from Kafka and processes them through a reactive pipeline.

During processing:

  1. Orders are received from a Kafka topic.
  2. Customer information is retrieved from an external API.
  3. Product information is retrieved from an external API.
  4. Redis is used for caching and distributed locking.
  5. Orders are validated and enriched.
  6. Final orders are persisted in MongoDB.
  7. Fault tolerance mechanisms protect external integrations.

The architecture is designed to support high-throughput workloads while maintaining resilience and scalability.


πŸ—οΈ Architecture Overview

flowchart LR

    Kafka["Kafka Topic"]

    Consumer["Kafka Order Consumer"]

    Processor["Order Processing Service"]

    Redis["Redis Cache & Distributed Locks"]

    CustomerAPI["Customer API (Go)"]
    ProductAPI["Product API (Go)"]

    MongoService["Order Storage Service"]

    MongoDB[("MongoDB")]

    Kafka --> Consumer

    Consumer --> Processor

    Processor --> Redis

    Processor --> CustomerAPI
    Processor --> ProductAPI

    Processor --> MongoService

    MongoService --> MongoDB
Loading

🎯 Architecture Highlights

  • Event-driven architecture using Apache Kafka.
  • Fully reactive processing pipeline powered by Spring WebFlux.
  • External service enrichment using customer and product APIs.
  • Redis used for caching and distributed locking.
  • Fault tolerance implemented with Retry and Circuit Breaker patterns.
  • MongoDB persistence with optimized indexing strategy.
  • Non-blocking asynchronous processing.
  • Designed for scalability and high-throughput workloads.

βœ… Key Features

  • Reactive Kafka consumer.
  • Order enrichment using external services.
  • Redis cache integration.
  • Distributed locking support.
  • MongoDB persistence.
  • Retry and Circuit Breaker with Resilience4j.
  • Reactive programming with Project Reactor.
  • Validation and business rules enforcement.
  • Event-driven processing model.

πŸ› οΈ Technology Stack

Backend

  • Java 21
  • Spring Boot 3.x
  • Spring WebFlux
  • Project Reactor

Messaging

  • Apache Kafka

Data Storage

  • MongoDB
  • Redis

Resilience

  • Resilience4j
  • Reactor Retry

External Services

  • Go APIs (Customer Service & Product Service)

Testing

  • JUnit 5
  • Mockito

πŸ“‚ Project Structure

src/main/java
β”‚
β”œβ”€β”€ config
β”œβ”€β”€ consumer
β”œβ”€β”€ service
β”œβ”€β”€ repository
β”œβ”€β”€ model
β”œβ”€β”€ dto
β”œβ”€β”€ mapper
β”œβ”€β”€ exception
└── util

βš™οΈ Setup

Requirements

  • Java 21+
  • Maven
  • Docker
  • MongoDB
  • Redis
  • Apache Kafka
  • Go

Configuration

Update the application configuration:

spring.kafka.bootstrap-servers=localhost:9092

spring.data.mongodb.uri=mongodb://localhost:27017/pedidosDB

spring.data.redis.host=localhost
spring.data.redis.port=6379

▢️ Run the Project

1. Start Infrastructure Services

Start:

  • Kafka
  • Redis
  • MongoDB

2. Start External Go APIs

From the /go-api directory:

go run main.go

Available endpoints:

GET /product
GET /customer

3. Start the Worker Service

mvn spring-boot:run

πŸ“ƒ Sample Payload

{
  "orderId": "order-100",
  "customerId": "Freyder-111",
  "products": [
    {
      "productId": "product-100",
      "name": "Iphone",
      "price": 2000
    }
  ]
}

πŸ§ͺ Testing

Run all tests:

mvn test

Covered scenarios:

  • Successful order processing.
  • Inactive customer.
  • Product not found.
  • Redis lock handling.
  • External service failures.
  • Retry execution.
  • Circuit breaker activation.

πŸ“ˆ Scalability and Optimization

MongoDB

  • Indexes on orderId
  • Indexes on customerId

Redis

  • Cache layer to reduce external API calls.
  • Distributed locks to prevent duplicate processing.

Kafka

  • Horizontal consumer scalability.
  • Asynchronous event processing.

Resilience

  • Retry policies.
  • Circuit Breaker pattern.
  • Graceful failure handling.

🌟 What This Project Demonstrates

  • Event-Driven Architecture.
  • Reactive Programming.
  • Distributed Systems Design.
  • Integration with External Services.
  • Fault Tolerant Applications.
  • Redis Caching Strategies.
  • Kafka Message Processing.
  • Modern Cloud-Native Backend Development.

πŸ‘¨β€πŸ’» Author

Freyder Otalvaro

Senior Software Engineer | Java | AWS | Distributed Systems

About

Reactive Java microservice for real-time order processing using Kafka, Redis, MongoDB, Go APIs, and Spring WebFlux with resilience and caching strategies.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors