Modern web applications architecture relies on building APIs and microservices in cloud infrastructures. This architecture is the primary standard adopted by the majority of software developers and architects, it also defines the behavior of an application and its entire data flow, but in spite of being effective they end up by bumping into some of the most significant needs of successful apps, scalability.
The Synchronous Gap
Most applications that use microservices and APIs as their primary data flow run the execution of their processes synchronously.
The main issue with synchronous applications is the increase of response time which causes a negative impact in user experience and an increase in the costs with cloud infrastructure, mainly if you’ve adopted a serverless architecture.
Here is an example of a synchronous API receiving a request for adding a new customer:
In this example, upon receiving a request for adding a new customer, the service executes the following actions in sequence:
- Validate the payload data;
- Insert the client in the application core database;
- Insert the client into the analytics database;
- Send a welcome email;
This strategy works, but in the long run with increasing application popularity, you have to deal with the following issues:
- Negative impact on user experience with increased execution time due to a large number of requests.
- Increase in the cloud infrastructure costs due to the allocation of more processing resources.
- The high complexity of code development and maintenance as the development team grows.
To create high-performance applications we can adopt the asynchronous development pattern.
Event-driven microservices to the rescue
Event-driven microservices are asynchronous by definition when adopting an event-oriented architecture, the developer should think about which triggers should perform actions.
A trigger can be a page view; an insert into a database or even an API call.
Actions are asynchronous and started with a trigger that can be anything from saving information in a database entity to calling another API. They could also run new triggers, this way event-driven microservices allows the creation of a reactive application.
In the previous example, we had an API request to create a new customer, consider this as an event trigger.
Upon receiving the “New Customer” trigger, the service executes the following actions:
- Validate the payload data;
- Insert the customer into the application’s core database;
- Emit a new asynchronous event called “user-created” then return a response to the client;
In this model, we isolate the minimum necessary operations for creating a new customer; any other actions are processed asynchronously in a new event.
By taking these actions, we improved the application response time and optimized the customer experience.
If you want to keep your analytics database on Google Cloud Platform your application database in Amazon RDS and your APIs on Digital Ocean servers, an event-driven architecture is the best way to integrate all of these platforms.
Adopting a multi-cloud environment means being ready to make use of the best available technologies, but you should be aware of the following:
- Disparate tools, consoles, and Technologies: Keeping track of all your services statuses may be painful.
- Expertise requirements: Each cloud platform has its technology and patterns, studying each one of these technologies thoroughly before implementing is mandatory.
- Operational Costs: The charging method of each cloud platform can also vary, you should get a deep dive in understanding all the possibilities of charging.
Auditing, controlling and ensuring the delivery of all events between different platforms can be a painful process and consume a considerable amount of development time. To gain speed and security in this development process, take a look at the Reactivehub development tools.
Event-driven microservices bring a new way of thinking about application architecture; they are incredibly configurable; fits in any product that should be scalable from the beginning and are ready for the new multi-cloud demands of modern high-performance applications.