Microservices: What Are They and Why Should You Care?

3 March 2015 · Indix Archive

First published on the Indix engineering blog. Original copy.

Over the last year, Microservices has emerged as a “new” approach to building large scale distributed systems. This is an introductory article that provides background on Microservices, their evolution, the pros and cons and the state of the art as it exists today.

You recently joined a brand new client project as a lead developer/architect. You’re sitting in a meeting room and after having heard the client’s requirements, you are now contemplating the right architecture and technology stack for the project.

Your client wants you to build an ecommerce application for consumers. They want to support multiple clients including browsers on desktop, and mobile including native mobile applications. In those cases, your system receives an HTTP request in either JSON or XML, it executes business logic, accesses database and sends back response in JSON or XML. At the same time, the system should also expose an API to integrate with third party applications.

“This sounds like a typical layered architecture”, you say to yourself. You have built a couple of such systems in the past, so you decide to use tried and tested architecture that you are comfortable with. The different layers of your architecture are divided into Presentation, Business and Database components. For the technology stack, you have a choice between Rails, Java, Scala, Node.js, and .NET. It really does not matter what you use as this architecture pattern is language or platform agnostic. However, your client wants you to release an MVP of the product within the next six months. In the end, you choose a technology stack that a majority of your team of four developers is at ease with.

Fast forward by six months. You are at a team party to celebrate the success of the MVP which was delivered on time. The team celebrates the success but also reflects on what a small team of six (you added two developers mid-way during the MVP) accomplished in a short time. The team is thankful to you for choosing the familiar technology stack. The layered architecture also provided multiple benefits. It was very easy to make a change as all the code was in a single source code repository.  For the same reason, it was easy for the two new developers to ramp up and set up the entire application on their laptop, build it and run it locally within a couple of hours. The release was also painless given that there was a single deployment pipeline that would take the build from the CI server and deploy it on a couple of load balanced production boxes.

Fast forward to two years later. After the success of the MVP and a few minor pivots later, the customer base of the product has grown. Your client also boosted its sales team in the last two years to aid the growth. And your team has grown to 20 developers. However, the product is not able to scale and evolve with the customer base. You realize that the application feels like a big ship that’s very hard to steer. The application has grown to thousands of lines of code. The ramping up of new developers is taking weeks instead of days. And you are finding it hard to track down developers who can work on your “legacy” codebase. As a result of all these factors, you are not able to deliver as fast as earlier to keep up with the business requirements.

Let’s try to understand what’s wrong with the application that you built. Let’s give it a name first. The term that is used to describe an application like the one above is- “Monolith”.

Below are some of the challenges associated with a large monolithic application.

Is there a solution?

Yes. Microservices – small autonomous services that work together, can be scaled and released independently with different teams potentially using different languages across different locations.

So, how do we describe a Microservice?

What’s with the term “Microservices”?

I heard the term “Microservices” for the first time when Fred George spoke about it in his talk at YOW 2012 – Brazil. Ronald Kuhn, the tech lead on Akka, thinks that Microservices as a term is too ambiguous and likes to call it Uniservices instead, given what it does.

Netflix used to call its implementation of Microservices as cloud native architecture and fine grained SOA but they have also started to use the term Microservices since that has become most widely accepted.

How is this different from Service Oriented Architecture (SOA)?

At the heart of it, both Microservices and SOA try to combat the challenges associated with large monolithic applications. SOA’s approach used protocols like SOAP, RPC, and a complex middleware called ESB that meant different things to different people. It had sound principles but there was a lack of consensus on how to do SOA. Moreover, implementation of SOA itself was monolithic where dumb services were integrated with a smart ESB. Proponents of Microservices look at it as a specific approach to SOA in the same way that XP or Scrum are different approaches for Agile software development.

Why now?

There was always a desire to build systems this way (even in the SOA era) but the recent advances and maturity in the areas of Cloud, DevOps and Continuous Delivery have made it easier to build them right with Microservices being the building blocks.

Moving towards Microservices

One has to delve into several design aspects and weigh the pros and cons of various approaches while moving towards microservices.

 

Microservices OSS Stack

Let’s talk about some OSS that’s available to help migrate towards Microservices.

If you are using Spring, the Spring Cloud Netflix project integrates these libraries into the Spring ecosystem.

The above list is not comprehensive and is focused on the JVM platform as majority of the Microservices at Indix run on the JVM. We are currently using Dropwizard and the Typesafe stack but are also actively evaluating the Neflix and Twitter stacks. We also have non-JVM microservices where we are using Bottle and Flask for Python, Express for Node.JS and Sinatra for Ruby.

What are the disadvantages?

The rosy picture I painted after the initial gloom might make you believe that Microservices would solve all your architectural problems. Sorry to break your heart, but like everything else in software, Microservices are not a silver bullet. It’s an architecture style that is still maturing and has its own share of challenges.

Should I move to a Microservice architecture?

This is one of those questions that has an YMMV (Your Mileage May Vary) answer.

At Indix, we started with a monolith (but modular) application which was built over the course of the last three years. As I write this article, we are migrating to microservices across all our teams. The reasons for us to move to microservices are captured in the section describing the problems with the monolith. In hindsight, starting with a monolith and breaking it down into microservices with the team growing and the system getting complex, seems like the right approach.

To provide a different perspective, I would refer to Go-CD – an open source build and release management tool. I worked on the team about three years back. Right now, it’s a six+ year old project and the codebase is still a monolith. I think the reason why it’s stayed so is because there were not more than ten developers at any given point of time. The team is co-located and would ramp up only two or three new developers every year. The team uses techniques like Branch by Abstraction and Strangler Approach to evolve with changing technological trends. It will be interesting to see if the community decides to split Go-CD into multiple Microservices at some point.

If you want to move towards a Microservices architecture, you should read Martin Fowler’s article on “Pre-requisites for Microservices”.

Summary

Microservices is an important tool in the arsenal of an evolutionary architect. Microservices themselves have evolved out of the hard earned lessons of engineers building large scale systems. When systems and teams scale, breaking them down into Microservices decouples your systems and gives more options and choices to evolve them independently. Like any other tool, it is important to know when and how to use it. Hopefully, this article has provided you enough context to decide on both.

Further Reading

If you are really interested in diving deeper into building Microservices, I suggest ordering a copy of the excellent book by Sam Newman called Building Microservices.