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.