What is a load-balaner?
This blog is for software technology-related topics and tutorials like: Software architecture (design), Problem statements, etc. Note: All the examples and topics are covered in Java.
Blog Archive
-
▼
2023
(10)
-
▼
May
(10)
- Load Balancer
- CAP Theorem in Distributed System
- Distributed Logging and Tracing in Microservices
- Saga Pattern for Distributed Transaction Managemen...
- Java 9 Module System
- Try With Resources Improvement in Java 9
- Switch Expression in Java 12
- Sealed Classes in Java 15
- Record Classes in Java 14
- Recursion
-
▼
May
(10)
Monday, 15 May 2023
Load Balancer
Wednesday, 10 May 2023
CAP Theorem in Distributed System
You cannot combine these three features all together “Cheap, Fast, and Good.
The CAP theorem applies a similar type of logic to distributed systems—namely, that a distributed system can deliver only two of three desired characteristics: consistency, availability, and partition tolerance (the ‘C,’ ‘A’ and ‘P’ in CAP).
A distributed system is a network that stores data on more than one node (physical or virtual machines) at the same time. Because all cloud applications are distributed systems, it’s essential to understand the CAP theorem when designing a cloud app so that you can choose a data management system that delivers the characteristics your application needs most.
Let’s take a detailed look at the three distributed system characteristics to which the CAP theorem refers.
Consistency
Consistency means that all clients see the same data at the same time, no matter which node they connect to. For this to happen, whenever data is written to one node, it must be instantly forwarded or replicated to all the other nodes in the system before the write is deemed ‘successful.’
Availability
Availability means that any client making a request for data gets a response, even if one or more nodes are down. Another way to state this—all working nodes in the distributed system return a valid response for any request, without exception.
Partition tolerance
A partition is a communications break within a distributed system—a lost or temporarily delayed connection between two nodes. Partition tolerance means that the cluster must continue to work despite any number of communication breakdowns between nodes in the system.
Tuesday, 9 May 2023
Distributed Logging and Tracing in Microservices
The microservice architecture pattern. Requests often span multiple services. Each service handles a request by performing one or more operations, e.g. database queries, publishes messages, etc.
How to understand the behavior of an application and troubleshoot problems?
Saga Pattern for Distributed Transaction Management in Microservices
This model lets the service manage domain data independently on a data store that best suits its data types and schema. Further, it also lets the service scale its data stores on demand and insulates it from the failures of other services.
However, at times a transaction can span across multiple services, and ensuring data consistency across the service database is a challenge.
Implement each business transaction that spans multiple services as a saga. A saga is a sequence of local transactions. Each local transaction updates the database and publishes a message or event to trigger the next local transaction in the saga. If a local transaction fails because it violates a business rule then the saga executes a series of compensating transactions that undo the changes that were made by the preceding local transactions.
There are two ways of coordinating sagas:
- Choreography - Event-Based (Message Broker)
- Orchestration - Command-Based (Service Provider)
Choreography-based saga
- The Order Service receives the
POST /ordersrequest and creates anOrderin aPENDINGstate - Then Order Service publishes an event to the message broker that an ORDER_CREATED to Payment Service.
- The Payment Service got the ORDER_CREATED event and does the necessary updates and publishes the event to Order and Restaurant Service that an ORDER_PAID.
- The Order and Restaurant Service got the ORDER_PAID event and do the necessary updates.
- The Restaurant Service publishes the event to Order and Delivery Service that an ORDER_PREPARED.
- The Order and Delivery Service got the ORDER_PREPARED event and do the necessary updates.
- Finally, Delivery Service publishes the event to Order Service that ORDER_DELIVERED to the Order Service, and the Order state changed from PENDING to COMPLETE.
- The Order Service receives the
POST /ordersrequest and creates anOrderin aPENDINGstate - Then Order Service sends the command to Orchestrator Service that an ORDER_CREATED to Payment Service.
- The Payment Service got the ORDER_CREATED command and does the necessary updates and sends the command to Order and Restaurant Service that an ORDER_PAID.
- The Order and Restaurant Service got the ORDER_PAID command and do the necessary updates.
- The Restaurant Service sends the command to Order and Delivery Service that an ORDER_PREPARED.
- The Order and Delivery Service got the ORDER_PREPARED command and do the necessary updates.
- Finally, Delivery Service sends the command to Order Service that ORDER_DELIVERED to the Order Service, and the Order state changed from PENDING to COMPLETE.