Skip to main content

Relationship between Facade Design Pattern and Microservices


Introduction:
This article reveals the relationship between facade design pattern and micro service architecture. Normally design patterns provide the solution for recurring problem in software design. In the same kind micro service architecture provides the solution for continuous delivery, highly scalable, secure, maintainable and independently deployable solution in software architecture world. The clean architecture or clean code comes after the principles and practices. The word ‘Independent’ plays a powerful role in all our design principle and practices, thus it is very important if we build large scale systems. Thanks to Uncle Bob and Peter Rodgers to provide such dimension in architecture and software design which lead us to develop and deploy error free, highly scalable application and chance of implementing new technologies in existing system. In this article I try to relate facade design pattern with micro service architecture.

Example Requirement

Let us consider this example requirement to understand the relationship in better way. Consider building a Notification System for a client. This system should able to send SMS, Mail and push kind of notifications to the end users and log in to database for reporting.

Facade Design Pattern

It is one of the Structural Design Pattern among the Gang of four design patterns. The word ‘Facade’ means front face of the house. In software design, it means exposing simple interface to the client by hiding the complexity of the system in the simplified way.

UML Class Representation

Description

All the complex modules like mail notification, smsnotification and push notification will not be exposed to client, instead they are encapsulated in facade class namely notification facade and this facade class can be explored to client.Simply, Notification Facade class is composed of mail notification, smsnotification and push notification classes. So the client will only aware of facade class. We can use this pattern when the system is very complex and difficult to understand. So, this will provide simple and straight forward solution to client in order to use complex system.

Micro service architecture

Thanks to Peter Rodgers to provide such fabulous architectural style of software development technique which comprised of service oriented style and is composed on two or more small independent services . In other words, the big system is divided into small systems and solely handled by small teams and these small systems were independent and have its own data store or storage. This architectural style is called as micro service architecture.
In architectural world, the traditional style is monolithic, where the system is huge and complex and it may contains read and write databases. Dependency between modules is high and so deployment of any module becomes timely taken process and risky. Day to day technologies is upgrading, and in monolithic scenario we will not get any chance of upgrading our system. So, we need to spend our time maintenance and bug fixing. Developing Test Driven Development system will be challenging to us in such tightly coupled systems. So, micro service architecture is comes to rescue to overcome all these monolithic problems.

Description

In Micro service architecture micro services will not be exposed to client instead it will interact with API Gateway. In other words, API Gateway encapsulates the micro services in order to provide simple API interface to client. Micro services are built on the top of the rest API and it can be implemented on any technologies and it has its own data store. Each micro service can be assigned to small team and from which they can independently develop and deploy their micro services without dependency of the others and so continuous delivery is proved in this aspect. The prime responsibilities of API Gateway are to authorize, route, orchestrate and steps if needed. When client requests API gateway, it will route to appropriate micro service based on the request. Before it will check for authorization, if the request has privileges then it will process the request. We can implement our own custom gateway or readymade gateways issued by cloud providers.

Relationship between Facade and Micro services

If we closely look into facade, modules or subsystem are simplified to client by means of facade class. So, client will not know anything about the complexity of the system. Certainly, a complex system can be split into small systems as micro services and it should have its own data store .For client, the API gateway will be the facade. The complex endpoints of the micro services will be encapsulated by means of API Gateway and so it will be single point of access to a complex system. The authenticity of request must be validated by API Gateway.

On the top micro services is designed for Service oriented architectural style and so our sub systemsmust designed for REST API’s but in facade design pattern , it need not to be an service orientedstyle.

Conversion of Facade to Micro services

It is not recommended for you to always convert facade to micro services which is usually a complex architecture when compare to monolithic type of architecture. We can convert the facade to micro services during these circumstances 
  • Independent Deployment- You decided to deploy sub modules or sub systems in different machines in order to provide scalability provision on demand. So that you can provide web farm scenario from where load balancer can handle the concurrent requests to a particular sub system.
  • Micro Team – You decided to hand over the sub system to a small team in an organization and it will be independent from the other and so that you can achieve continuous delivery of that particular sub system.
  • Testable – The small system can be independently testable and so you can improvise the quality of that sub system which is not depending on the others.
  • Migration – Initially you planned for MySQL data store for a sub system .later period you have plan for migration of MySQL to MSSQL or any kind of commercial databases.

Real World Example

Consider the notification system is highly demand and complex system .From where you need to hand over notification sub system to different teams like SMS , email and push kind of notifications and also you need to have continuous deliverable, scalable, in dependable kind of system . Then you can choose the micro service architecture and so that you can hand over the responsibilities to different teams. All systems endpoint will be encapsulated by mean of custom gateway and provide simplified access to the client by hiding the complexity of the system. Your converted system will look like these

Advantages

The following advantages are there in the converted architecture.

  • Independent Deployment
  • Highly scalable
  • Maintainable
  • Continuous delivery
  • Heterogeneous technologies
  • Heterogeneous Databases
  • Small team
  • Custom API Gateway to simple interface for an client- facade
  • Test Driven Development
  • Loosely coupled services

Disadvantages

These are the following disadvantages
  • Becomes more complex system when micro services increases.
  • API Gateway will be challenging
  • Orchestration will be more complex in order to accommodate micro service changes
  • Handling transaction across micro services and datastores will be difficult.

Conclusion

I hope this article is helps you to understand the relationship between facade pattern and micro service architecture. In case of any feedback, please do let me know by commenting below which will be helpful for me to shape this article in better way.

Comments

Popular posts from this blog

How to resolve ASP.NET core web API 2 mins timeout issue

Introduction We are in the new world of microservices and cross-platform applications which will be supported for multiple platforms and multiple heterogeneous teams can work on the same application. I like ASP.NET Core by the way its groomed to support modern architecture and adhere to the software principles. I am a big fan of dot net and now I become the craziest fan after seeing the sophisticated facility by dot net core to support infrastructure level where we can easily perform vertical and horizontal scaling. It very important design aspect is to keep things simple and short and by the way, RESTFul applications are build and it is a powerful mantra for REST-based application and frameworks. Some times we need to overrule some principles and order to handle some situations. I would like to share my situation of handling HTTP long polling to resolve the ASP.Net core 2 mins issue. What is HTTP Long polling? In the RESTFul term, when a client asks for a query from the serv

How to Resolve ASP.NET Core Key Protection Ring Problem in AWS Lambda

Introduction When it comes to server less web application design using asp.net core razor pages, we definitely need to consider a factor of data protection key management and its lifetime in asp.net core. I developed a site using AWS toolkit of ASP.NET Core Razor Pages. The main advantage of ASP.NET Core is cross-platform from where we can deploy our application in MAC, Linux or windows. I deployed my site initially in IIS Server from which I got the results as expected .but later period I decided to host my site in AWS Lambda in order to meet our client requirement. Strangely, I got unexpected behavior from my site. I just refer the cloud information Lambda Log to identify or pinpoint the case, I got the error Information like “Error Unprotecting the session cookie” from the log. In this article, I tried to explain the root cause of the problem and its solution to overcome such kind of issue. Data Protection in ASP.NET Core This is feature in ASP.NET Core which acts as repl

Which linq method performs better: Where(expression).FirstorDefault() vs .FirstOrDefault(expression)

 Introduction When it comes to LINQ, we always have multiple options to execute the query for the same scenario. Choosing correct one is always challenging aspect and debatable one. In one of our previous articles   Any Vs Count  , we have done performance testing about best LINQ methods over .NET types. In this article, I would like to share about  Where(expression).FirstorDefault() vs .FirstOrDefault(expression) Approaches Performance testing for  Where(expression).FirstorDefault() vs .FirstOrDefault(expression) is very interesting IEnumerable<T> or ICollcetion<T>  .FirstOrDefault(expression) is better than  Where(expression).FirstorDefault() Public API To check the performance, I need some amount of data which should already available. So I decided to choose this  public api . Thanks to publicapis Public API Models Entry class using System ; using System.Collections.Generic ; using System.Text ;   namespace AnyVsCount { public class Entry { pub