Skip to main content

Posts

Showing posts from November, 2026
Building an Idempotent Kafka Consumer with Spring Boot 3: Preventing Duplicate Event Processing in Distributed Systems Kafka makes communication between microservices reliable and scalable, but handling messages correctly when failures occur is a different challenge. A consumer can receive the same event more than once, even when the producer publishes it only once. This behaviour is expected in systems that use at-least-once message delivery. Consider an order-processing service that receives an event indicating that a payment has been completed. The consumer updates the order status and records the payment. If the application crashes after committing the database transaction but before committing the Kafka offset, Kafka can deliver the event again. Without an idempotency mechanism, the application may execute the same business operation twice. In this article, we will build a database-backed idempotent Kafka consumer using Java 21, Spring Boot 3, Spring Kafka, PostgreSQL an...

Architecture Deep-Dive: Implementing Clean Multi-Tenancy with ThreadLocal in Spring Boot 3 & Java 21

 Building an enterprise SaaS backend in Java requires addressing multi-tenancy early in the development lifecycle. Handling isolation purely at the query level without a unified architectural pattern leads to data leaks, scattered tenant_id WHERE clauses, and unmaintainable code. In this guide, we break down how to implement context-isolated multi-tenancy using an X-Tenant-ID header, a ThreadLocal context, and Spring Security filters in Spring Boot 3 & Java 21. The Problem: Accidental Tenant Bleed When scaling a B2B SaaS platform, queries must be partitioned so Tenant A never reads Tenant B’s records. Passing tenantId manually as a method parameter across Controllers, Services, and Repositories introduces cognitive load and human error. The solution is an ambient context pattern: Intercept the HTTP request. Extract the authenticated user's organization/tenant ID. Bind it to the current executing thread. Access it seamlessly in JPA layers or Auditing hooks. Clear the contex...

Top Modern Cloud Platforms to Deploy Full-Stack & Spring Boot Apps in 2026

Cloud Deployment Guide Stop burning runway on bloated AWS bills. Here is how modern engineers ship containers and APIs with zero financial waste. Building a robust backend with Java 21, Spring Boot, or Python is only half the battle. When it comes to deploying live without running into unexpected cloud invoices, picking the right infrastructure matters. Here is a curated breakdown of high-performance, cost-effective hosting platforms for 2026. 1. DigitalOcean: Reliable Linux & Docker Control $4 - $6 / mo The gold standard for full root access. If you need complete control over a Linux VPS, Docker containers, MySQL databases, or self-hosted local AI engines like Ollama, DigitalOcean Droplets deliver consistent performance. Best for: Microservices, multi-container Docker Compose, and persistent storage. Advantage: Dedicated IPv4 address, simple backup snapshots, zero cold starts. ...