Posts

Reactor or Dispatcher pattern.

Image
What is the reactor design pattern? As the name suggests, it reacts to the client request. And dispatch the client's request to the right service. In more technical words, it demultiplex different requests to different services. It is one of the many ways to implement event-driven architecture. The reactor design pattern teaches us how to handle multiple clients synchronously. Different clients can ask for different services from the server — the reactor pattern decuple request handling and despatching to a particular service. The reactor maintains a lookup table, which is a kind of map which holds pointers to concrete event implementations. Though which we can call hooked methods when event occurs. The reactor pattern cannot scaleup much, because it does serialization at the demultiplexing layer. We can create one reactor or dispatcher for multiple events, or we can create multiple  reactors, one per event. In case of multiple reactors, each reactor has its synchronous

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 a synchronous   -  half-

Monitor Object or Thread-safe passive object pattern

Image
Background -  Object is an instance of a class. That class may have many methods. Monitor object make sure, only one method of class can execute at a time. Monitor object helps in case many threads are accessing a single object. Monitor object pattern also helps to achieve serialization at the function level. There are many benefits to using it.  With monitor object pattern, we can avoid the old style of pooling (looping through based on one shared boolean variable), which is a waste of CPU time. Monitor object puts the thread in sleep mode until other concurrently executing methods notify it. Through this, we can also define the  execution   sequence of methods of a class. The good part is, now clients (who before pooling to get notified) don't have to worry about notification and serialization. Monitor object class can take care of all these issues. How Monitor object achieve it? In OOP, we learned to access data members of a class through API only. It means data mem

Socket programming

Image
It is a small prerequisite of reading my blogs on Pattern-Oriented Software Architecture volume-2 book. If you want to read this book, It is even required. In this blog, I have explained three different scenarios of client-server communication over TCP-IP. I have used windows socket to implement the code. My intention here is not to discuss the theory of socket programming. I am just giving you a very basic implementation so that you can use this code to learn distributed patterns on a client-server based system on socket programming. If you are interested in reading the basic theory of socket programming before go ahead, please read this link . You are sending and receiving one massage at a time. Please click on the image to see the zoom view. It's the first and most straightforward example where you send a small packet request to the server and wait for its response. You are sending large files from client to server. Please click on the image to see the z