Half-Sync Half-Async architectural pattern

Synchronous application - 

Creating synchronous services is easy for developers, as they follow a single execution path. Debugging is also easy, as developers know the execution flow by seeing the code. Creating only synchronous services is not good (primarily if your OS and HW supports event-driven architecture, it is okay if you have an embedded system with limited space and no multi-threading environment), as it is slow and time-consuming, synchronous way of execution slow down your application. 


Asynchronous application - 

Creating a fully asynchronous system is not always possible. Though they are fast and efficient. But hard to develop, especially when the user is actively involved/interacting with your application. It is challenging to create asynchronous, high-level (or say user level) APIs. But asynchronous way speed up the execution and your application become faster if you develop an excellent asynchronous model.


Mix of synchronous and asynchronous  - 

half-sync and half-sync pattern suggests to create a system, a mix of asynchronous, and synchronous system.

Half-Sync half-Async architectural pattern give us idea, how we can develop application, which is not as complicated as asynchronous system, but it leverages the efficiency of asynchronous system by implementing most of low-level service through it. And not slow as a synchronous system, but leverages the simplicity of synchronous systems, by making high-level APIs synchronous.

How it works?

Divide the services into two parts. Run the synchronous service in a separate thread. Create a queue between synchronous and asynchronous services and communicate through queuing the requests. 

It follows the layer patternMostly high-level services fall under synchronous way of execution, and down the line, internal or low-level services through asynchronous way of execution.

Example

To be added.

Thanks for reading it. To learn more about design patterns and basic design principles, please see my web page.

Comments

Popular posts from this blog

Non-virtual interface idiom (NVI)

Factory method design pattern for beginners.

Architectural patterns => Mud to structure => layers.