Microservices Design: Get Scale and Availability Right
Microservices Design: Get Scale and Availability Right
One of the central ideas of using microservices is to be able to scale quickly and effectively. Read on to find out how you can accomplish this and get it right the first time.
Join the DZone community and get the full member experience.Join For Free
There's been an almost exponential growth in our customers’ interest in microservices and containers, even though we’re still in the early days of their use.
The promise of microservices is that you can divide and conquer the problem of a large application by breaking it down into its constituent services and what each one actually accomplishes. Each can be supported by an independent team. You get to the point where you can break the limits on productivity that Fred Brooks described in his book, The Mythical Man-month.
Aside from being able to throw more people at the problem and — unlike what Brooks observed — actually become more efficient once you get a microservices-based application into production, you can quickly start thinking about how to scale it. Think resiliency and high-availability. And you can easily determine what services don’t need scaling, or high availability.
These things become easier than with a large, monolithic application, because each microservice can scale in its own way. Here are my insights about these variables, and the decisions you may face in designing your own microservices platform.
How Do You Know When to Scale a Microservice?
The nice thing about running in a microservices environment is that you don’t have to scale everything in order to scale something. You may have some services in your application that don’t need to scale at all. They may be fine running as a single service (or as a dual instance service, simply for failover). On the other hand, you may have many services that really do need to scale, to the tune of a dozen or hundreds of instances of a particular service.
For example, your shopping website has many features you want to present to users as they are browsing and shopping. You probably have a recommendation service, which provides options that might attract users according to their search terms or current web page. Now, you can make that recommendation service part of your entire monolithic application, or you can break it off into its own service. It’s the same with the shopping cart service and the avatar service that may show users a pre-selected image of themselves when they log into their accounts.
But when you think about the work that the avatar service must do, it’s not much. It must search through a repository of images, and return a particular user’s image. This is a well-understood requirement that doesn’t need to scale.
On the other hand, the recommendation service is going to be more complex, and fairly heavy-weight. Each user session presents a new set of variables. What is similar when they search for product A? What do they end up buying when they search for product B? There’s much more data involved, more querying, all part of a more compute-intensive capability. This is very different, from a scaling perspective, when compared to a tiny avatar service that simply hands out a JPEG file every time that’s requested during a user session.
Give Every Service Its Own Level of Availability
With microservices, you don’t need the same availability for each service. Not everyone will talk about this, because you may not want to say to your team “service A doesn’t have to be as available as service B.” But at the end of the day, the shopping cart had better be highly available, or your customer won’t purchase anything. But if the avatar service suddenly isn’t available, and instead shows a blank box, customers probably are either going to buy fewer things or leave your site altogether.
The point is, you can have different requirements for your services in terms of uptime, scalability, delivery frequency, and more.
Use Purpose-Fit Technology Stacks
There are many things that are good, and interesting, about microservices. As separate services, they only communicate over the network, which means that you can use completely different technology stacks to support each one.
You can determine what’s fit for purpose using a key-value store, for example, if that’s important. If you’re using a relational database for your shopping cart service, you’re probably doing credit card authorization, which involves a bit more of a technical stack than if you’re doing recommendations based on a big data analytics engine.
Think how that compares when you use a monolith. You need to make a lot of compromises. You’re going to have to pick one technology stack that works for every problem you have to solve, which means it’s difficult for organizations to adopt and use new technologies. If I need to revise some feature within my monolith, I’m not going to rewrite the whole thing just so that I can use some cool new framework. But with a microservices architecture, that isn’t an issue.
The Right Size, Complexity for a Microservice Is…
Whey I get asked what I think is the right size or level of complexity for a microservice, as I often do, I tell them that, as a general rule of thumb, you should be able to have a small team rebuild it, from scratch, in a few weeks. That means doing it within one sprint, or maybe two at most. With that focus, you can adopt new technologies to replace or augment parts of your application architecture.
In the monolith scenario, you’re much more constrained in your technology choices, simply because one size must fit all. But when you break down the problem into more fundamentally independent pieces, you can use the technologies that best fit the service.
That flexibility is a great benefit.
Published at DZone with permission of Anders Wallgren , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.