Container Patterns
- Get link
- X
- Other Apps
Why we need Container Patterns:
Due to popularity of microservices and distributed computing, containerization has become a major trend in software development. It involves encapsulating or packaging software code and all its dependencies so that it can run uniformly and consistently on any infrastructure.In distributed architecture which consists of many microservices, we want our microservices business focused and keep non functional aspects like security, service discovery, proxy, logging and platform configuration etc out of our microservices code, container patterns evolved.
There are 2 popular patterns:
- Sidecar
- Ambassadors
Sidecar pattern:
In this pattern, we schedule a workload on the same hosts which is intended for specific things that don’t concern your application. There are various use cases for sidecar patterns like request authentication/authorization, service discovery, adding HTTPS to legacy service.
Usecase: We will discuss here example of updating static website content on webserver without rebuilding docker image in kubernetes cluster.
Kubernetes pod supports multiple containers with shared volumes. We are going to make use of this concept to accomplish our requirement. That is, we would be creating a separate container called sidecar which is responsible for downloading the latest content from repository periodically or on demand based on configuration. Once it is downloaded, it will place the new content for the application server container to access in the shared volume and all our clients will be able to see latest contents without rebuilding container image.
Ambassadors:
An ambassador container brokers interactions between the application container and the rest of the world. As with other single-node patterns, the two containers are tightly linked in a symbiotic pairing. It transfers the responsibility to distribute the network load, retries, or monitoring to something else. Here the containers are coupled means without ambassador pattern, the application cannot contact the outside world. This is the pattern you'd use when you want microservices to interact with one another. They don't know exactly where other microservices are; they just know they can find them by name. And for that, they need a service discovery. This discovery could be at the DNS level, or it could be at an application level.
Usecase: Lets assume we have one database server which is not able to handle the application load. We want to shard the data but without changing application.
Sharding splits up the data into multiple disjoint pieces, each hosted by a separate machine. One approach is to build all of the sharding logic into the sharded service itself. In this approach, the sharded service also has a stateless load balancer that directs traffic to the appropriate shard. Effectively this load balancer is a distributed ambassador as a service. The alternative is to integrate a single-node ambassador on the client side to route traffic to the appropriate shard. We can introduce an ambassador container that contains all of the logic needed to route requests to the appropriate storage shard. Thus, your front end or middleware application only connects to what appears to be a single storage backend running on localhost.
Another interesting applications of an ambassador-type container is in the deployment architecture called Canary: let’s imagine we want to test the deployment of a new version of our microservice, transferring only a small percentage of the total requests. This deployment mode can be managed with a container ambassador who rotates the desired percentage of traffic to the new container.
In nutshell, Whether it is to extend the functionality of our microservices or to mediate access to a service on which it depends, the most suitable solution is to introduce a dedicated, business logic independent and reusable container. There are lots of different use cases and implementation pattern available when working with microservice architecture, we need to choose wisely whatever is suitable to our use case.
- Get link
- X
- Other Apps



