← Back to all selected work
Spring BootKafkaKeycloakPostgreSQLDockerKubernetesAvro

Event-Driven E-commerce Microservices Architecture

Decoupled microservice cluster powered by Kafka Avro serialization, Keycloak 24 OAuth2 gateway, and Resilience4j circuit breaking.

Organization Personal Engineering Project
Role System Designer & Backend Engineer
Timeline Nov 2024
6 Services Microservices
Keycloak 24 Auth Server
Kafka + Avro Event Pipeline
Zipkin + Prometheus Tracing

Context & Engineering Challenge

Synchronous inter-service HTTP communication creates tight coupling: when inventory verification or payment gateways slow down, order placement threads exhaust connection pools and crash the entire platform.

Hard Constraints

Order creation response time must remain invariant under downstream dependency outages. Schema modifications between services must be strictly backward and forward compatible.

System Architecture

EVENT-DRIVEN MICROSERVICES CLUSTER Spring Cloud Gateway OAuth2 Resource Server Validates JWT from Keycloak Keycloak 24 IAM Realm · Roles · Tokens APACHE KAFKA CLUSTER Confluent Schema Registry Topic: order-events (Avro) Topic: inventory-events Order Service PostgreSQL · Flyway Inventory Service Resilience4j Circuit Breaker Notification Service Async Consumer Queue

Architecture Decisions & Trade-offs

Asynchronous Event Sourcing with Kafka & Avro

Decoupled checkout processing from inventory allocation using Apache Kafka. Events are serialized with Apache Avro schemas registered in Confluent Schema Registry for strict contract validation.

Alternatives Evaluated: Considered REST calls with retry policies; rejected because retry storms exacerbate downstream database saturation.

Spring Cloud Gateway OAuth2 Resource Server

Consolidated authentication and route authorization into an API Gateway acting as a stateless OAuth2 resource server validating JWT tokens issued by Keycloak 24.

Alternatives Evaluated: Considered service-to-service mTLS without central gateway; rejected due to high configuration complexity in development environments.

Resilience4j Circuit Breakers & Dead Letter Queues

Configured circuit breakers with fallback queues: when inventory lookups exceed latency thresholds, orders enter a pending state and inventory is reconciled asynchronously without dropping customer orders.

Alternatives Evaluated: Considered failing fast with immediate 503 errors; rejected due to lost customer conversions.
RETROSPECTIVE & FUTURE DIRECTIONS

What I would do differently

TODO: Divyanshu to reflect on scaling choices (e.g. Saga orchestrator vs choreography, multi-region Kafka replication).