• Skip to main content
  • Skip to primary sidebar
BMA

BeMyAficionado

Inspire Affection

Principles Of Microservices: Culture Of Automation

September 2, 2020 by varunshrivastava Leave a Comment

This article is written in a succession of the previous article that talks about the first principle of microservices i.e. modelling of microservices around a business domain.

Once you have modelled the microservices around your business models and you are confident that you have done a good job, then the next step is to focus on automating your infrastructure.

Automation is very important in the world of microservices.

Since there are multiple services that have their own lifecycle and interdependencies. It is much more important to automate the entire pipeline of integration and deployment.

Table of Contents

  • Principle 2 – Culture of Automation
    • Continuous Integration
      • Benefits Of Continuous Integration
      • Guidelines to Ensure Smooth Integration
    • Mapping Continous Integration To Microservices
      • Small Enterprise
      • Medium Enterprise
      • Large Enterprise
    • Continuous Deployment
      • Environment Agnostic Build Artefacts
      • Functionality doesn’t change across environments
  • Conclusion

Principle 2 – Culture of Automation

Deploying a monolith application is a fairly straightforward process. You have everything packaged into one and boom the app is deployed. But with Microservices, it’s a whole another story.

With the increasing number of microservices in an enterprise with their interdependence can make it a complex process and a developer’s life miserable. That is why we need to leverage the technologies that allow us to automate all of this. I’m talking about a culture of automation using CI and CD.

Continuous Integration

CI became the need of the hour with the advent of microservices architecture.

With CI, the core is to keep everyone in-sync with each other by making sure that the newly checked-in code integrates well with the existing code.

This is done by performing a series of verification steps performed on the newly checked-in code to see if the code compiles successfully, whether the test cases are green and more… If you are not using CI, then working with multiple teams and multiple services is going to be painful and nasty.

Benefits Of Continuous Integration

There are many benefits of Continuous Integration:

  • Faster feedback – You can the feedback within minutes whether the code that you have checked-in integrates well with the existing code.
  • Code Quality – You can attach Continuous Inspection tool such as SonarQube for that will check the quality of your code and also let you know any loophole or possible security vulnerability.
  • Automatic Artifact Generation – It will automatically generate the build artefacts and preserve it. This way you can perform a series of verification and integration testing on the same code. This is really helpful as every artefact have a unique version number attached so you can be sure that the testing is performed on the same artefact which was generated.
  • Recreate the Artefacts On-Demand – Every build is version controlled. So in case you need to go back to the old build artefacts, you can do it easily. It is as easy as navigating to the old version and build again.
  • Keep Track of All The Stages – You can keep track of all the stage that is performed so far. This gives you a clear picture of the process; Build is a success or not; artefacts generated or not, artefacts uploaded successfully or not; Which tests were performed etc…
Stage View of Jenkins Pipeline
This is a Stage View of Jenkins Pipeline

Guidelines to Ensure Smooth Integration

There are certain guidelines that we follow in ThoughtWorks that ensures that the integration is smooth.

  • Check-in code to the mainline end-of-everyday – Checkin the code that you have worked on at the end of the day.
  • Have a suite of tests to validate your changes – There is no use if the code is syntactically correct but disobeys the behaviour of the application. So always make it a habit to write a unit test for the changes you make. Following articles will help you to start with Test Driven Development.
    • Mindset Behind Test-Driven Development
    • LinkedList Implementation In TDD Way
    • Shopping Cart Application In Java
  • Fixing the Broken Build Should Be Your Number One Priority – The mantra is – Never leave the office with a broken build. Once more changes are pushed over the broker build the harder it gets to find the bug and resolve it. So make sure you fix the broken build first and then carry on with the development.

Mapping Continous Integration To Microservices

This topic is so vast that it could be a chapter in itself. But I would keep it short and crisp and only talk about different mapping schemes that are used at different size enterprise.

Let’s divide the mapping schemes based on the size of the organization as small, medium and large.

Small Enterprise

I’m mentioning this technique for small organizations but I have personally seen this model getting used in some of the massive code bases as well.

Image result for small sweet home
Small Enterprise or Startups

The small enterprise is the one where there is less number of teams (1-3-5).

There is the simplest solution for such an enterprise and that is to use Single Source Code Repository and CI build for all different microservices.

It looks like this:

Single Source Code Repository and CI Build For All Microservices

It has a very simple build model.

Just one monolithic build for all the microservices.

Any check-in to this source code repository will trigger the build for all. It will produce artefacts for all the microservices tied with the same build number.

As you can see in the image all the artefacts are tied to the same build number build-123.

A very simple model; Fewer Repositories to worry about; And conceptually simple build;

One commit is all that a developer has to worry about at any given time.

As I said, this will work with a single team in a small enterprise. But with bigger enterprise comes more microservices and more teams. Then this model has significant downsides.

Downsides of this model

  • More Build Time – A single line of change in any of the service builds all three services.
  • More Artefacts – Change in any of the services will result in the generation of artefacts for all the services. This consumes more disk space.
  • Deployment Logics Become Complex – Identifying which service is changed and deploying just that service requires complex logic. You will have to read the commit messages, compare them to see which is changed and then deploy the changed one. It is better to deploy all three artefacts together but that is specifically what we need to avoid.
  • Single Point Of Failure – If anyone microservice is broken then it won’t allow others to build either. This will hinder parallel development.
  • Difficult for Multiple Teams to Work Together – As every team is dependent on each other, it is hard to manage multiple teams.

Medium Enterprise

This approach is a slight variation of the approach we talked above. In this approach, there is a single Repository with all the code with different CI build settings.

This is achievable with a well-defined structure. You can link different parts of the source tree with different build pipelines.

A single source repo with subdirectories mapped to independent builds
A single source repo with subdirectories mapped to independent builds

This approach seems to be better than the one we discussed before. Because now every build pipeline is different. So, if user service is broken, it wouldn’t have any effect on the Catalog service build.

Another advantage of this approach is that it deals with only one repo. So, it is easier to check-in/out code. All you have to maintain is the single repository. But this is a blessing in disguise. Because as much it enables the developers to check-in code frequently, it also enables them to push the code linked with more than one service in the single commit.

And this happens more than often.

But, don’t worry there is a third approach as well.

Large Enterprise

I would recommend this technique for building and deploying the microservices.

Using one source code repository and CI build per microservice
Using one source code repository and CI build per microservice

In this, each microservice have their own codebase. They have their own build and test pipeline. If I make any code changes than I only have to worry about just one microservice, one artefact and I get clear ownership of it.

If you want to take a step further, you can also keep the associated test cases in the same repository. This way you will know which test is associated with which microservice.

So far we have covered just one part of the Automation i.e. Continous Integration. Let’s look into continuous deployment as well.

Continuous Deployment

As your artefact moves through different stages of the CI & CD, it will be deployed into different environments.

Most of the times, when you are working for a big client or in a distributed architecture, there are more than 3 or 4 environments where you will have to deploy your code and test.

Talking in broad terms, there will be 3 environments at least; dev, qa and prod.

In most of the legacy systems that (that I’ve worked on), it has some automation tool like Chef or Ansible that takes care of prepping the environment for the applications.

Those tools have all the configurations which are required by your application to run such as JVM, JDK, Tomcat server, configuration files, user setup and so on. It sure sounds easy, but maintaining that configuration for all these environments itself is a cumbersome task. And it is very important to have some kind of policy such that every configuration that is made to those templates goes through the pipeline with all the important checks in place.

Overview of Chef Architecture
Overview of Chef Architecture

But that is about prepping the environment (host server) on which your artefact is going to run.

Now imagine what would happen if you would have to build different artefacts for different environments. If this is your build strategy then you have opened yourself into a lot of confusion.

You will have to keep track of every build. You might also want to create a different organization for your artefacts. Such that the dev related artefact will be published to the dev artifactory, the stage will be published to stage artifactory and so on… On top of that, you have to maintain the last working version on all the three environments. For that, you will have to come up with another maintenance strategy.

Environment Agnostic Build Artefacts

Dev QA and PROD enviroments

This can easily be achieved by decoupling the configuration from the code.

The only difference between these environments is the configuration values such as user credentials, database connection strings, service URLs etc… if you can externalize these properties in your application then you can have a single build artefact that can be deployed anywhere.

Functionality doesn’t change across environments

Every language has some kind of build artefact associated with it. Like Ruby has gems, Java has JARs and WARs and Python has eggs. These artefacts are just the bundle multiple files that are executed on the runtime.

These artefacts only need a suitable runtime to execute. These artefacts need not know about the environment. It should be the job of the environment to provide them with the required information at runtime. This way these artefacts can become environments agnostic.

There are two ways of providing this environment-specific configuration to your application –

  • Set the environment variables before deploying the artefact. This can be done using your deploy tool (Jenkins, GOCD, etc). You can create a different stage for setting the environment variables. These environment variables can be read from the external vault.
  • Another way of providing the config is via cloud-config servers. Spring Cloud Config is one such service that is responsible for providing the configuration values to the application at runtime.

This way you can have one build that can be deployed anywhere.

These are the main aspects that need to be considered before automating your deployment pipeline.

Conclusion

In this part of the series (Principles of Microservices), we talked about the Culture of Automation that is very essential when it comes to microservices.

Every enterprise will have more than 10 or 20 microservices (and this number keeps growing) and it can very easily overwhelm the developers if proper automation techniques are not in place.

The above-mentioned techniques will help the organization to keep a consistent development environment where developers will be able to focus only on code.

Related

Filed Under: Programming Tagged With: automation, culture of automation, microservices, principles of microservices

Primary Sidebar

Subscribe to Blog via Email

Do you enjoy the content? Feel free to leave your email with me to receive new content straight to your inbox. I'm an engineer, you can trust me :)

Join 874 other subscribers

Latest Podcasts

Recent Posts

  • Is The Cosmos a Vast Computation?
  • Building Semantic Search for E-commerce Using Product Embeddings and OpenSearch
  • Leader Election with ZooKeeper: Simplifying Distributed Systems Management
  • AWS Serverless Event Driven Data Ingestion from Multiple and Diverse Sources
  • A Step-by-Step Guide to Deploy a Static Website with CloudFront and S3 Using CDK Behind A Custom Domain

Recent Comments

  • Varun Shrivastava on Deploy Lambda Function and API Gateway With Terraform
  • Vaibhav Shrivastava on Deploy Lambda Function and API Gateway With Terraform
  • Varun Shrivastava on Should Girls Wear Short Clothes?
  • D on Should Girls Wear Short Clothes?
  • disqus_X5PikVsRAg on Basic Calculator Leetcode Problem Using Object-Oriented Programming In Java

Categories

  • Blogging
  • Cooking
  • Fashion
  • Finance & Money
  • Programming
  • Reviews
  • Software Quality Assurance
  • Technology
  • Travelling
  • Tutorials
  • Web Hosting
  • Wordpress N SEO

Archives

  • November 2024
  • September 2024
  • July 2024
  • April 2024
  • February 2024
  • November 2023
  • June 2023
  • May 2023
  • April 2023
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • November 2021
  • September 2021
  • August 2021
  • June 2021
  • May 2021
  • April 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • February 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016

Tags

Affordable Hosting (4) algorithms (4) amazon (3) aoc-2020 (7) believe in yourself (4) best (4) database (4) earn money blogging (5) education (4) elementary sorting algorithms (4) experience (3) fashion (4) finance (6) Financial Freedom (7) food (7) friends (3) goals (5) google (5) india (10) indian cuisine (5) indian education system (4) java (16) life (16) life changing (4) love (4) make money (3) microservices (9) motivation (4) oops (4) podcast (6) poor education system (4) principles of microservices (5) problem-solving (7) programmer (5) programming (28) python (5) reality (3) seo (6) spring (3) success (10) success factor (4) technology (4) top 5 (7) typescript (3) wordpress (7)

Copyright © 2025 · Be My Aficionado · WordPress · Log in

Go to mobile version