Posts

Showing posts with the label SystemDesign

Understanding the Hash Ring in Consistent Hashing

Image
 If you’ve ever looked into distributed systems or scalable caching, you’ve probably heard the term hash ring . It’s at the heart of consistent hashing — the algorithm that powers systems like DynamoDB, Cassandra, Riak, and distributed caches such as Memcached and Redis Cluster. In this post, we’ll break down what a hash ring is, how it works, and why it matters. What Is a Hash Ring? A hash ring is a conceptual circle that represents the entire range of hash values. Imagine the numbers from 0 to 2³² − 1 arranged in a circle. Nodes (servers) : Each server in your cluster is hashed to a point on the ring based on its identifier (e.g., IP address). Keys (data items) : Each key you want to store (e.g., cache key, user ID) is also hashed to a point on the ring. Assignment rule : A key is assigned to the first server found clockwise from its hash position. https://ably.com/blog/implementing-efficient-consistent-hashing Adding a Node When you add a new node: Hash the node’...

Understanding CQRS with Real-Life Examples

Image
  1. CQRS in an Online Store (Real-Life Example) In this diagram, we see an online store architecture applying CQRS: API Gateway : The entry point for all client requests. It routes incoming calls to the right backend service. Frontend Service : Connects to various backend services depending on the operation. Products Service (Write Side) : Responsible for updating product information (e.g., adding new products, changing prices, updating stock). Products Search Service (Read Side) : Maintains a denormalized, read-optimized view of product data so customers can quickly search and filter products. Reviews Service : Handles user reviews separately, but it also feeds into the search service so that reviews can be displayed alongside products. Notice that the Products Service and the Products Search Service do not share the same database. Instead, updates from the Products Service trigger events (via message queues or change notifications), and the Search Service...