Posts

Showing posts from December, 2019

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