Posts

Low Water Mark and High Water Mark in System Design

When designing large-scale distributed systems , we deal with thresholds all the time — memory, queues, replication logs, caches, and network buffers. Two key concepts that help maintain stability and efficiency are High Water Mark (HWM) and Low Water Mark (LWM) . They are critical in replication protocols, messaging queues, and quorum systems . 🔹 High Water Mark (HWM) In system design, HWM is the maximum threshold at which the system takes corrective action to avoid overload or inconsistency. It prevents overflow , ensures stability, and protects resources. 🔹 Low Water Mark (LWM) The LWM is the safe lower threshold that signals the system has recovered enough to resume normal operations . It prevents rapid toggling between "block/unblock" states (avoids thrashing). 🔹 Why Do We Need Both? The gap between HWM and LWM (called hysteresis ) ensures smooth control. Without it, systems would keep toggling rapidly whenever they touch the threshold. 🔹 Application...

WebSocket vs gRPC: A Detailed Guide to Modern Communication Protocols

In today’s world of distributed applications, microservices, and real-time user experiences, communication protocols are the backbone of scalable systems. Two prominent technologies stand out for client-server and service-to-service communication: WebSockets and gRPC . While both aim to improve data exchange efficiency, they differ fundamentally in architecture, performance, and ideal use cases. Let’s dive deep into both. 🔹 What is WebSocket? WebSocket is a full-duplex communication protocol built over TCP, enabling persistent connections between client and server. Unlike HTTP (request-response), WebSocket allows real-time bidirectional communication . Key Characteristics: Protocol : Works over TCP (ws:// or wss:// for secure). Persistent connection : Once established, the connection remains open. Full-duplex : Both client and server can send messages anytime. Text & Binary : Supports JSON, text, and binary data. Browser-friendly : Widely supported in modern ...

Singular Update Queue: A Smarter Way to Handle Updates

In modern systems, efficiency and consistency are key. Whether you are building a database engine, a high-performance backend service, or a user-facing application, the way you handle updates can make a huge difference in system stability and responsiveness. One elegant pattern that often emerges is the Singular Update Queue . What is a Singular Update Queue? A Singular Update Queue is a mechanism where multiple update requests targeting the same resource are funneled into a single queue , ensuring updates are: Serialized – executed in strict order, preventing race conditions. Consolidated – redundant or frequent updates are batched together. Efficient – avoids re-processing the same data multiple times. Instead of having multiple threads or services updating a resource simultaneously, a single queue ensures that only one update is processed at a time . Why Use a Singular Update Queue? Avoid Race Conditions Concurrent writes can corrupt state. A queue ensure...

Ensuring Missing Resources Are Created Automatically in a Spring Boot Project

Image
In a Spring Boot application , many resources—like directories, files, database tables, or cloud resources—are essential for the app to function correctly. But what if these resources don’t exist? Without them, your application may fail or behave unexpectedly. The good news: Spring Boot provides mechanisms to automatically create missing resources at startup . Let’s explore how to handle different scenarios. 1. Automatically Creating Directories Applications often need directories for file uploads, logs, or temporary storage. You can ensure these directories exist using Spring’s lifecycle hooks : import jakarta.annotation.PostConstruct ; import org.springframework.stereotype.Component ; import java.io.File ; @Component public class DirectoryInitializer { private static final String UPLOAD_DIR = "uploads"; @PostConstruct public void init() { File dir = new File(UPLOAD_DIR); if (!dir.exists()) { boolean created = dir.mkdirs(); ...