<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sachin Kokkarachedu on Medium]]></title>
        <description><![CDATA[Stories by Sachin Kokkarachedu on Medium]]></description>
        <link>https://medium.com/@sachinkokkarachedu?source=rss-f6579c4cce81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Eu5amFDJFAM4TX0x</url>
            <title>Stories by Sachin Kokkarachedu on Medium</title>
            <link>https://medium.com/@sachinkokkarachedu?source=rss-f6579c4cce81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:15:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sachinkokkarachedu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Scalable Microservices Architecture with Spring Boot, Eureka, Kafka, and More]]></title>
            <link>https://medium.com/@sachinkokkarachedu/building-a-scalable-microservices-architecture-with-spring-boot-eureka-kafka-and-more-c659be7cc2c4?source=rss-f6579c4cce81------2</link>
            <guid isPermaLink="false">https://medium.com/p/c659be7cc2c4</guid>
            <category><![CDATA[microservices-application]]></category>
            <dc:creator><![CDATA[Sachin Kokkarachedu]]></dc:creator>
            <pubDate>Thu, 24 Apr 2025 17:27:06 GMT</pubDate>
            <atom:updated>2025-04-24T18:57:49.909Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In this blog, I walk you through a comprehensive microservices-based project I developed using the Spring Boot ecosystem, including Spring Cloud Gateway, Eureka Discovery Server, Kafka for asynchronous communication, and Prometheus/Grafana for monitoring. This project showcases how to build a production-ready system with scalability, observability, and resilience baked in.</p><h3>🏢 Project Overview</h3><p>The application simulates an e-commerce platform comprising six independent services:</p><ul><li><strong>Product Service</strong> — Manages product catalog</li><li><strong>Order Service</strong> — Handles order placement</li><li><strong>Inventory Service</strong> — Checks stock availability</li><li><strong>Notification Service</strong> — Sends async notifications on order events</li><li><strong>API Gateway</strong> — Single entry point for external clients</li><li><strong>Discovery Server</strong> — Eureka registry for service discovery</li></ul><p>Each service is packaged as an independent Spring Boot application and communicates via REST or Kafka.</p><h3>📌 Tech Stack</h3><p>Language — Java 17</p><p>Framework — Spring Boot, Spring Cloud</p><p>Service Discovery — Netflix Eureka</p><p>API Gateway — Spring Cloud Gateway</p><p>Database — MySQL</p><p>Circuit Breaker — Resilience4j</p><p>Authentication, Authorization, Security — Keycloak</p><p>Distributed Tracing — Micrometer, Zipkin</p><p>Event driven architecture/Messaging — Apache Kafka</p><p>Observability — Zipkin, Prometheus, Grafana</p><p>Containerization — Docker</p><h3>🌍 Architecture Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-tofjgSqic130AYtY91zg.png" /></figure><h3>🧩 Microservice Highlight: Product Service</h3><p>The Product Service is responsible for managing product data in the system. It’s built using <strong>Spring Boot</strong>, connected to a <strong>MySQL</strong> database, and follows a clean separation of concerns.</p><p>📌 <strong>Tech Stack</strong>:</p><ul><li>Java 17, Spring Boot</li><li>Spring Data JPA (Hibernate)</li><li>MySQL</li><li>Eureka Client</li><li>Lombok for boilerplate reduction</li></ul><p>📂 <strong>Code Structure</strong>:</p><ul><li>ProductController handles REST API requests.</li><li>ProductService contains business logic.</li><li>ProductRepository abstracts DB operations.</li><li>Product is the JPA entity mapped to the database.</li></ul><p>🔐 <strong>Configuration</strong> (from application.properties):</p><ul><li>Connects to a MySQL container named mysql</li><li>Registers with Eureka Discovery</li><li>Enables distributed tracing via Zipkin</li><li>Exposes metrics via Prometheus Actuator endpoints</li></ul><p>🚀 <strong>Exposed APIs</strong>:</p><ul><li>POST /api/product – Adds a new product</li><li>GET /api/product – Lists all products (DTOs used for clean separation)</li></ul><p>📊 <strong>Observability</strong>:</p><ul><li>Tracing enabled via <strong>Zipkin</strong></li><li>Health checks and metrics via <strong>Spring Actuator + Prometheus</strong></li></ul><h3>🧩 Microservice Highlight: Order Service</h3><p>The Order Service handles the core workflow of placing an order. It ensures inventory availability, persists the order, and notifies downstream services — all while staying resilient and asynchronous.</p><p>📌 <strong>Tech Stack</strong>:</p><ul><li>Java 17, Spring Boot (Web &amp; WebFlux)</li><li>MySQL, JPA (Hibernate)</li><li>Kafka (event-driven communication)</li><li>Eureka Discovery Client</li><li>Resilience4j (circuit breaker &amp; time limiter)</li><li>Prometheus, Zipkin (observability)</li></ul><p>📂 <strong>Key Components</strong>:</p><ul><li>OrderController exposes the /api/order endpoint.</li><li>OrderService implements the business logic:</li><li>Checks stock availability with <strong>Inventory Service</strong></li><li>Publishes an event to Kafka for <strong>Notification Service</strong></li><li>DTOs separate request/response layers</li><li>Circuit breaker and timeout wrappers for external API reliability</li></ul><p>📊 <strong>Observability &amp; Resilience</strong>:</p><ul><li>Uses <strong>Zipkin</strong> for tracing and <strong>Prometheus</strong> for metrics</li><li>Circuit breaker config for inventory ensures fallback and resilience</li></ul><p>📡 <strong>Event-Driven</strong>:</p><ul><li>Publishes OrderPlacedEvent to Kafka on successful order creation</li><li>Decouples communication from Notification or Billing services</li></ul><p>🔐 <strong>Configurable Properties</strong>:</p><ul><li>Fully configured via application.properties</li><li>Environment ready for Docker deployment and cloud-native readiness</li></ul><h3>🧩 Microservice Highlight: Inventory Service</h3><p>The Inventory Service is a key internal component that ensures products are in stock before an order is placed. It provides real-time availability checks for a list of SKUs.</p><p>📌 <strong>Tech Stack</strong>:</p><ul><li>Java 17, Spring Boot</li><li>Spring Data JPA + MySQL</li><li>Eureka for service discovery</li><li>Prometheus + Zipkin for observability</li></ul><p>📂 <strong>Core Components</strong>:</p><ul><li>InventoryController: Accepts GET requests to /api/inventory with SKU codes</li><li>InventoryService: Queries the database and returns whether each SKU is in stock</li><li>InventoryRepository: JPA interface abstracts DB logic</li><li>InventoryResponse: DTO used for returning clean, simple results</li></ul><p>⚙️ <strong>Config Highlights</strong>:</p><ul><li>Connected to a MySQL container (inventoryservice DB)</li><li>Registers with Eureka for service discovery</li><li>Exposes Prometheus metrics and Zipkin tracing</li></ul><p>🔍 <strong>Endpoint Behavior</strong>:</p><ul><li>GET /api/inventory?skuCode=SKU1,SKU2</li><li>Returns:</li></ul><pre>json<br><br>[   <br>  { <br>    &quot;skuCode&quot;: &quot;SKU1&quot;, <br>    &quot;isInStock&quot;: true <br>  },   <br>  { <br>    &quot;skuCode&quot;: &quot;SKU2&quot;, <br>    &quot;isInStock&quot;: false <br>  } <br>]</pre><p>🚀 <strong>Design Insight</strong>:</p><ul><li>Lightweight and fast — optimized for frequent checks from Order Service</li><li>Uses functional mapping to convert DB results into DTOs</li><li>All reads are wrapped in a read-only transactional context for safety</li></ul><h3>🧩 Microservice Highlight: Notification Service</h3><p>The Notification Service is a lightweight consumer of asynchronous order events. It listens to Kafka for new order placements and acts on them (e.g., sending notifications or triggering follow-up workflows).</p><p>📌 <strong>Tech Stack</strong>:</p><ul><li>Java 17, Spring Boot</li><li>Kafka (Spring Kafka)</li><li>Jackson (JSON parsing)</li><li>Prometheus (Monitoring)</li><li>Docker-ready</li></ul><p>📡 <strong>Kafka Listener</strong>:</p><ul><li>Subscribed to topic: order-placed-topic</li><li>Consumes messages as part of notificationGroup</li><li>Uses Jackson to deserialize events into OrderPlacedEvent POJOs</li></ul><p>🧠 <strong>Event Handling Logic</strong>:</p><pre>@KafkaListener(topics = &quot;order-placed-topic&quot;, groupId = &quot;notificationGroup&quot;)<br>public void handleOrderPlaced(String message) {<br>    OrderPlacedEvent event = objectMapper.readValue(message, OrderPlacedEvent.class);<br>    // Print or send notification<br>}</pre><p>📈 <strong>Monitoring</strong>:</p><ul><li>Exposes metrics and health info using Spring Actuator</li><li>Prometheus scraping enabled</li></ul><p>🚀 <strong>Design Insight</strong>:</p><ul><li>Asynchronous, decoupled communication with Order Service</li><li>Focused on scalability and responsiveness</li><li>Easy to scale horizontally by adding consumers in the same group</li></ul><h3>🧩 System Backbone: Discovery Server</h3><p>The Discovery Server is built using <strong>Spring Cloud Netflix Eureka</strong>. It acts as the central registry where all microservices register and discover each other.</p><p>📌 <strong>Tech Stack</strong>:</p><ul><li>Java 17, Spring Boot</li><li>Spring Cloud Eureka Server</li><li>Prometheus, Zipkin</li><li>Spring Security (basic auth)</li></ul><p>📂 <strong>Highlights</strong>:</p><ul><li>Runs on <strong>port 8761</strong></li><li>Annotated with @EnableEurekaServer</li><li>Services (like order, product, inventory) auto-register here</li><li>Can be accessed at: http://localhost:8761 (with basic auth)</li></ul><p>🔐 <strong>Security</strong>:</p><ul><li>Secured using basic auth</li></ul><pre>spring.security.user.name=eureka<br>spring.security.user.password=password</pre><p>📈 <strong>Observability</strong>:</p><ul><li>Tracing enabled via <strong>Zipkin</strong></li><li>Exposes Prometheus metrics for system-wide monitoring</li></ul><h3>🧩 System Gateway: API Gateway</h3><p>The API Gateway is the entry point for all clients accessing the system. It’s built on <strong>Spring Cloud Gateway</strong> and is fully integrated with OAuth2 for security, Eureka for service discovery, and observability tools for monitoring.</p><p>📌 <strong>Tech Stack</strong>:</p><ul><li>Java 17, Spring Cloud Gateway</li><li>Eureka Client</li><li>OAuth2 Resource Server (JWT)</li><li>Zipkin + Prometheus</li></ul><p>📂 <strong>Route Configuration</strong>:</p><ul><li>Routes to product-service, order-service, and discovery-server</li><li>Example:</li></ul><pre>Path: /api/product/** → product-service via Eureka</pre><p>🔐 <strong>Security</strong>:</p><ul><li>JWT authentication through Keycloak or similar</li><li>OAuth2 Resource Server support</li></ul><p>📈 <strong>Observability</strong>:</p><ul><li>Metrics via Prometheus</li><li>Tracing via Zipkin</li></ul><p>💡 <strong>Design Insight</strong>:</p><ul><li>Keeps microservices behind a unified entry point</li><li>Decouples client logic from internal architecture</li><li>Easy to apply common filters (rate limiting, auth, etc.)</li></ul><h3>📊 Monitoring &amp; Observability</h3><h3>Prometheus &amp; Grafana</h3><ul><li>Prometheus scrapes metrics from each service</li><li>Grafana visualizes metrics and custom dashboards</li></ul><h3>Zipkin</h3><ul><li>Visual trace of requests across services</li><li>Configured in each service for full tracing</li></ul><h3>🔧 Dev &amp; Build Configuration</h3><p><strong>Project Structure:</strong> Multi-module Maven project</p><p><strong>Parent POM Highlights:</strong></p><ul><li>Spring Boot 3.4.3</li><li>Spring Cloud 2024.0.1</li><li>Testcontainers for integration testing</li></ul><p><strong>Plugins:</strong></p><ul><li>Spring Boot Maven Plugin</li><li>Lombok for boilerplate reduction</li></ul><h3>✅ Learnings &amp; Takeaways</h3><ul><li>Effective use of Spring Cloud tools for production-readiness</li><li>Clean separation of responsibilities across services</li><li>Real-world usage of Kafka for async, decoupled workflows</li><li>Observability is <strong>not optional</strong> — Prometheus and Zipkin are must-haves</li><li>Circuit breaker pattern (Resilience4j) ensures fault tolerance</li></ul><h3>👩‍💼 Key Highlights:</h3><p>This project is fully Dockerized, observable, and built for scale.</p><ul><li>Spring Boot Framework</li><li>Microservices Architecture &amp; Design Patterns</li><li>Distributed systems</li><li>Cloud-native development</li><li>Event-driven architecture</li></ul><p>You can find the source code on GitHub <a href="https://github.com/SACHINK51/microservices-project">[link here]</a>, and feel free to fork or contribute!</p><p><strong>Challenges I faced:</strong></p><ul><li>Handling async communication with Kafka and ensuring <strong>event delivery reliability</strong></li><li>Configuring secure JWT validation with <strong>OAuth2 Resource Server &amp; Keycloak</strong></li><li>🔎 Debugging distributed trace flows with Zipkin — helped me understand <strong>latency bottlenecks</strong></li><li>🔄 Ensuring smooth <strong>service registration and discovery</strong> across Docker containers using Eureka</li></ul><p><strong>Behind the Scenes (the real grind):</strong></p><ul><li>Countless hours <strong>debugging circuit breaker behavior (Resilience4j)</strong></li><li>Tracing failing service registrations in <strong>Eureka under Docker networks</strong></li><li>Troubleshooting Kafka message loss and consumer configs</li></ul><h3>📢 Call to Action</h3><p>If you’re a Recruiter, Software Engineer, Project Manager interested in microservices, I’d love to hear your thoughts. Connect with me, leave a comment, or shoot me a message!</p><blockquote><em>Let’s build better systems — one service at a time.</em></blockquote><blockquote>Thank you for reading!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c659be7cc2c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>