Circuit Breaker Pattern

As the name suggests, the “circuit breaker” is a design pattern in software architecture, which has gain prominence in the distributed environment.

MCB
Miniature Circuit Breaker

Circuit Breaker Pattern in detail

Almost each one of us knows about the MCB – miniature circuit breaker that is used in our homes. Its function is to break the electric supply of a particular circuit – either of a room or of an entire house – if it detects some anomaly in the electric supply or usage. Once the anomaly is removed, we can restore earlier state and the electricity resumes.

In this design pattern, there’s a component named “Circuit Breaker” which does exactly same. It acts as a proxy for certain function/API calls. If the call fails beyond a certain threshold, this component starts returning an error to the caller, even without checking if the proxied function/API is working.

Unlike MCB, this being a software component, it can be made more intelligent. This Circuit Breaker component can have a threshold and timeout defined. Once the error rate crosses the threshold, the component starts returning an error to the caller for a timeout period. After that, it tries to call the proxied function/API few times. If successful, it can slowly resume the service over a period of time.

Circuit Breaker
Circuit Breaker diagram – Source: https://martinfowler.com/bliki/CircuitBreaker.html

But, wait, wouldn’t it cause a problem for the users?

It could. However, in the distributed architecture, failure is always a possibility. This design pattern teaches to embrace failure rather than denying the possibility of failure. The overall architecture can handle such failures gracefully. e.g. if a service providing recommendations for titles of movies or books, you could easily show something else or not show anything at all. That would still allow your users to use the overall application – albeit w/o some functionality. This would anyway be better than failing entire application.

Also, the component can include the monitoring feature as well. This can push data about the failure rate to a central dashboard, which will allow administrators to check the failed components and take corrective measures.

Example of Circuit Breaker Pattern

Netflix has implemented this pattern very effectively and has also released the library which provides various functionalities they are using internally – Hystrix. There are some very good articles available which are mentioned in the links below.

Related Links

Related Keywords

Microservices Architecture, Hystrix, API Gateway

 

Edge Computing

Edge computing is distributed architecture methodology which brings some very specific advantages due to the distributed nature of the architecture. Using this architecture, businesses can enjoy benefits such as lower latency, reduced network bandwidth usage and near real-time processing of time-critical data.

Edge Computing
Edge Computing!! Ain’t it funny??

But what is Edge Computing after all?

With the rise of IoT (Internet of things) we are having several sensors or devices located at multiple locations. These sensors collect a massive amount of data. The businesses need to analyze and use this data for further processing. If all sensors are to send data to central server continuously, that would mean each one will need uninterrupted internet connectivity. It will end up in consuming huge network bandwidth. Also, sending data over the internet would also involve latency, which at least in certain cases may not be acceptable. All these things are expensive from a business perspective and here Edge Computing comes into the picture.

In this architecture, the collected data is processed near the edge by deploying some compute power – which could be low cost – near to the devices. This is referred as Device Edge. On these local machines, the data received could be received through local networks, not necessarily needing internet. Collected data could be processed near real-time and only actionable data is sent back to the central server immediately. Rest of the data could be archived as per the need on a periodic basis. As you can see, by deploying compute power near the devices, we have addressed all the three issues mentioned above.

There is another variant of Edge Computing. In above example, “Edge” is treated as an edge of the network where devices are located. Whereas in this other variant, “Edge” is treated as an edge of the cloud infrastructure. A close example of this is CDN – the static contents are cached on various edges across the globe and served based on geolocation of the request. However, CDN doesn’t involve any computing power.

There are some concerns about the security of the data at the edge locations, however, with careful planning, those could be handled satisfactorily.

Related Links

Related Keywords

Software Architecture, Cloud, IoT

Django

Django is a web app framework built using Python language. It is free and open-source (BSD license) framework used by many leading and well-known websites.

Django
Django Developer at work

What are the features of Django?

It uses Model-View-Controller architecture. The framework consists of:

  • Object-relational-mapper (ORM) which connects the data model with backend database (Model).
  • Web templating system to process HTTP requests (View)
  • URL dispatcher (Controller)

Being a framework, it also includes several components to ease the creation of complex web apps such as authentication module, web server, form component, cache module, support for XML and JSON representations and many more. As an addon, the distribution also contains tools to generate RSS/Atom feeds, Google Sitemaps, built-in mitigation for several vulnerabilities and also administrative interface.

Django framework implicitly enforces a certain way of developing your application, which might be construed as a limitation. However, this in itself maintains the sanctity of the code that is getting developed and keeps the code readable/maintainable even for your teammates.

Which websites are using Django framework?

The list is impressive. Disqus, Bitbucket, Instagram, Mozilla Firefox. Even Pinterest was built using Django, which later was migrated to Flask, another web app framework.

Alternatives for Django:

  • Flask
  • Falcon
  • Ruby On Rails
  • Laravel
  • Spring MVC
  • ASP .NET MVC

Why would you choose Django?

This framework is written in Python, which is easy to learn and also is one of the most popular languages. Built-in components and supporting modules make the development of the web app very fast. The add-ons provide the modules required for security. However, one of the important features of Django is template inheritance! You can define a base template and extend it for your further use.

Trivia

  • It is pronounced as Jango (D is silent with emphasis on J)
  • It was created in 2003 by two developers working at a newspaper.
  • It was made open source and Django Software Foundation was formed to maintain the software.
  • Framework as has been named after a guitarist  Django Reinhardt.

Related Links

Related Keywords

Web App Frameworks, Python, MVC, Software Architecture, Flask, Falcon