Event Driven Microservices
A brief history behind microservices
Before Microservices there were so called Monolithic Applications!
A Monolithic Application is a single-tiered software application in which the user interface and data access code are combined into a signle program from a single platform. A monolithic application is self-contained and independent from other computing applications. The design philosophy is that the application is responsible not just for a particular task, but can perform every step needed to complete a particular function
What is a Microservice?
It is a software engineering approach that focuses on decomposing an application into single-function modules with well defined interfaces.
Microservice Architecture is an architectural development style that allows building applications as a collection of small autonomous services developed for a business domain. As the name implies, a microservices architecture is an approach to building a server application as a set of small services. That means a microservices architecture is mainly oriented to the back-end, although the approach is also being used for the front end. Each service runs in its own process and communicates with other processes using protocols such as HTTP/HTTPS, WebSockets, or AMQP. Each microservice implements a specific end-to-end domain or business capability within a certain context boundary, and each must be developed autonomously and be deployable independently. Finally, each microservice should own its related domain data model and domain logic (sovereignty and decentralized data management) and could be based on different data storage technologies (SQL, NoSQL) and different programming languages.
What size should a microservice be?
When developing a microservice, size shouldn't be the important point. Instead, the important point should be to create loosely coupled services so you have autonomy of development, deployment, and scale, for each service. Of course, when identifying and designing microservices, you should try to make them as small as possible as long as you don't have too many direct dependencies with other microservices. More important than the size of the microservice is the internal cohesion it must have and its independence from other services.
Why a microservices architecture?
In short, it provides long-term agility. Microservices enable better maintainability in complex, large, and highly-scalable systems by letting you create applications based on many independently deployable services that each have granular and autonomous lifecycles.
Benefit of using Microservices
- Every unit of the entire application should be the smallest, and it should be able to deliver one specific business goal,
- Service Startup is relatively quick,
- Fault isolation is easy. Even if one service goes down, other can continue to function,
- More hardware resources could be allocated to the service that is frequently used.
- Data is federated. This allows individual Microservice to adopt a data model best suited for its needs,
- No cross-dependencies between code bases. You can use different technologies for different Microservices.
Service Discovery and Load Balancer
Introduction of Load Balancer and Service Discovery
By looking the diagram above, if we need more hardware resources to a specific service, most of the time on this architecture we end up deploying new instances of the same service. By doing that we increes the performace of our solution. In this diagram there is a big problem. What I mean with this? Managing the base_urls of all services we have in the front part is a big problem. If we go like this we will end up on something soo called url hell. We are increasing the performance but by doing it we are having a lot of problems during the maintainents. Because of having these problems there were introdused two services 'Load Balancer' Service and 'Service Discovery' Service.
What is Load Balancer?
A load balancer manages the flow of information between the server and an endpoint device (PC, laptop, tablet or smartphone). A load balancer is a hardware or software solution that helps to move packets efficiently across multiple servers, optimizes the use of network resources and prevents network overloads.
Using a load balancer provides the following benefits
- Flexibility to adjust for changing needs.
- Ability to scale beyond initial capacity by adding more software instances.
- Lower cost than purchasing and maintaining proprietary hardware appliances. Software can run on any standard hardware or virtual machine, which tends to be cheaper.
- Consistent load balancing capabilities across multiple cloud environments.
Load Balancer In Cloud
Using a cloud load balancer provides a managed application networking solution in the cloud that can draw resources from a network of elastic load balancers and servers. Cloud computing also allows for the flexibility of hybrid, hosted, and multi-cloud solutions. They could be deployed on-premises as well as in the cloud and managed centrally.
What is Service Discovery Service?
Microservices service discovery is a way for applications and microservices to locate each other on a network. Service discovery implementations within microservices architecture discovery includes both:
- a central server (or servers) that maintain a global view of addresses,
- clients that connect to the central server to update and retrieve addresses.
EDA
Event-Driven Architecture
Event-Driven Archtecture is a paradigm that promotes Events. Events are states of something that happened. On EDA events are delivered in near real time, so consumers can respond immediately to events as they occur. Producers are decoupled from consumers — a producer doesn't know which consumers are listening. Consumers are also decoupled from each other, and every consumer sees all of the events.
Event Streaming Microservices
When business events occur, producers publish them with messages. At the same time, other services consume them through event listeners.
Benefits
There are tons of benefits of using Event Streaming Microservices, some of them are listed bellow
- Loosely coupled structure,
- Complete isolation of the microservices,
- No synchronous REST calls,
- Asynchronous event-driven functionality,
- Performance gain.
All the units must be separated enough (loosely-coupled). Otherwise, microservice architecture won’t work and your system will turn into a distributed-monolith.
Downsides
Single point of failure (Event Service/Event Store/ Messaging Broker/DSP)
- Must construct Event Service as a Cluster
- Enable persistence for Topics (Queues)