Posts

Load Balancers in System Design

Image
When building scalable and reliable systems, one of the most critical components is the load balancer. Its job is simple yet powerful: distribute incoming network traffic across multiple servers so that no single server becomes overwhelmed. This ensures smooth performance, high availability, and a better user experience. 🔑 Key Functions of a Load Balancer Traffic Distribution : Spreads requests evenly across servers. Redundancy & Reliability : Keeps services available even if one server fails. Scalability : Makes it easy to add or remove servers as demand changes. Health Monitoring : Continuously checks server status to avoid routing traffic to unhealthy nodes. Session Persistence : Ensures a user’s session stays on the same server when needed. SSL Termination : Offloads encryption/decryption tasks from backend servers. 🛠️ Types of Load Balancers Hardware Load Balancers   Physical devices dedicated to balancing traffic. Often used in enterprise setups.   Software Load Ba...

Database Sharding

Database Sharding: Scaling Your Data the Smart Way As applications grow, databases often struggle to handle massive amounts of data efficiently. Database sharding is a powerful architecture pattern that solves this problem by splitting large datasets into smaller, more manageable chunks called shards . These shards are distributed across multiple machines or database nodes, improving scalability and performance. Why Do We Need Sharding? Handles big data workloads Improves query performance Enables horizontal scaling Provides fault isolation Types of Database Sharding           1. Key-Based Sharding                   Data is distributed using a hash function.                      Example : `application_id % 3` → three shards.           2. Range-Based Sharding            ...

Things to know for System Design

What is System Design? System design is the process of defining the architecture, components, and interfaces of a system to meet specific requirements. Here's a brief breakdown: Identify Requirements: Determine what the system needs to do. High-Level Design: Outline the system's major components and their interactions. Detailed Design: Specify the internal workings of each component. Implementation: Write the code and integrate the components. Testing: Verify that the system meets all requirements and functions correctly. Maintenance: Update and improve the system over time. Functional vs Non-Functional Requirements Functional : Basic functionalities that the system should offer Non-Functional : Quality constraints in application like portability, maintainability, reliability, security etc. What are the components of System Design? Architecture : The overall structure of the system, including how components interact and the flow of data. Components : The individual parts of the...

Event Handling in Spring

Spring's event handling is single-threaded so if an event is published,  until and unless all the receivers get the message, the processes are blocked and the flow will not continue. [Synchronous] Four things necessary for an event: Source : to publish the event in Spring - ApplicationEventPublisher object Event : event must extends from ApplicationEvent // springframework 4.2 + - - any object  Listener : IOC container Handler : Handler method must annotated with @EventListener Creating, publishing and handling custom events in Spring Create an event class, `CustomEvent` by extending `ApplicationEvent`. This class must define a default constructor which should inherit constructor from ApplicationEvent class. import org.springframework.context.ApplicationEvent; public class CustomEvent extends ApplicationEvent {     public CustomEvent(Object source) {         super(source);    }    public String toStri...

JMS: Deep dive in MQ systems and Roadmap to Kafka

Image
JMS: Java Messaging Service JMS is an example of Messaging Systems based on asynnchronous design pattern which is used by microservices to interact with each other to send data and events. For introductory part, please refer  here . JMS allow applications to create and send, receive and read messages in a shared environment. JMS: Programming Model Basic components to develop client based producer and consumer system are: ConnectionFactory : Use the Java Naming and Directory Interface (JNDI) to find a ConnectionFactory object, or instantiate a ConnectionFactory object directly and set its attributes. Based on delivery model, client has separate instance for connection factory to create a connection to a provider: Point to point :  QueueConnectionFactory Publish/subscribe: TopicConnectionFactory             The following snippet of code demonstrates how to use JNDI to find a connection factory object: Context ctx = new Init...

Enterprise applications - Need of messaging service and JMS

Why we need messaging system in enterprise applications ? If applications have dependency i.e microservices depends on each other for resources, then we need RPC , hence RPC systems were made. Remote procedure call (RPC) systems, including Java RMI, are synchronous i.e the caller must block and wait until the called method completes execution, and thus offer no potential for developing loosely coupled enterprise applications without the use of multiple threads. In other words, RPC systems require the client and the server to be available at the same time. However, such tight coupling may not be possible or desired in some applications. Message-Oriented Middleware (MOM) systems provide solutions to such problems. They are based on the asynchronous interaction model, and provide the abstraction of a message queue that can be accessed across a network. Note, however, that messaging here refers to asynchronous requests or events that are consumed by enterprise applications and not humans...

Creating a Web Application

Image
Generally, a web application starts with a login portal or registration portal, otherwise we could use simple html pages for rest things out there. Our first web application will be starting with a login portal, interacting with database through a servlet with validation and login error handling . Requirements : An IDE (most preferably Eclipse J2EE)   Server (Apache Tomcat) // link to download is given in previous blog post. Database (most preferably MySql 5.5) Follow the steps below and code to create a login page : 1. Open Eclipse Enterprise edition. File -> New -> Dynamic Web Project . 2. Enter project name and choose a new runtime which is the server itself. 3. Select server name and specify it’s directory in the system. 4. click next, and put build/classes as the output folder (by default it’s same written here) and then next, check the web.xml for deployment description purpose. 5. Click on Fin...