What Are Microservices? And Why You'll Love Them
Learn how microservices make development, deployment, and testing easier.
Join the DZone community and get the full member experience.Join For Free
So, you have this awesome app. Everyone loves it. You know it, I know it. It's just the bee's knees. Awesome! But now, because you made the COOLEST thing ever, more people are using it. That increased traffic has stressed your servers, but more importantly it's stressing out the company because "We can't scale fast enough." What are you to do? Well I'd be a horrible "blogger" if I didn't at least try to help. So let's give this post the ol' college try.
Microservices, as the name suggests, are REEEEEALLY small services that make up a single application. Actually, the size (read number of lines of code) is a hard thing to pin down. Basically instead of building millions of lines of code (a monolithic app), you break out the app into logical sections that all perform a specific job. There is no set definition for what constitutes a microservice. It's more of a guideline, kinda like REST. Is your app doing all the things? Is your app only deployable as a single entity? Then you're probably looking at a monolithic app. Can you scale a single part of your app to meet current load? Are you able to redeploy just a small subset of your app when you have a new release? Then that's probably a microservice. Here's why you'll love them.....
Source: Decentralized Data.
Reason 1: Any Language
The first reason I can think of is that microservices don't care what the other microservices are written in. You LOVE elm. Why? I don't know, but you do. But another team just can't get enough of the Gems included in Rails. Perfect! Just make sure the data that is sent from microservice A is structured in the way that microservice B is expecting. You could write each service in a new and exciting language if you wanted. I wouldn't, but I'm not going to tell you how to live. That's your PM's job.
Reason 2: Simplified Testing
The second reason microservices make sense to me is testing. Have a wonderful NullPointerException laying somewhere in the stack trace? Way to go. But did it come from <insert your favorite file here> or from <that file you hate so much>? Who knows. Time to go on a code safari and find out. With microservices, you get an error in service B. Cool! Well B is sent data from A. SOOOO, that means that either A sent the data incorrectly or B spazzed out and threw the error. That means you don't have to look at C-ZZ. That saves some time. Now you're less frustrated when you actually find the issue. That's always nice.
Reason 3: Deploying Made Easy
This is the last reason because I'm running out of focus on this post so I need to wrap it up. Deploying is made easier. When you make a change to a service, you just need to deploy that one service, NOT the entire application. This means less downtime and better user experience. Something's broken, have something new to roll out? Awesome! Just a few clicks and it's out in the wild. This ease of deployment also leads to easier scaling. Your users are using a lot of eventing right now? No worries! Just scale up the service that handles events like webhooks and polling and no one will be the wiser that that one customer who always brings down events was overloading the service for the third time this month.
Lastly, then I promise to let you get back to vastly more entertaining things like watching paint dry. When should do you this? When should you make microservices? If you are working on a monolithic app and paying off some of that technical debt (shameless plug of my own blog, I know), now is the perfect time. Take a hard look at what has been built. Is it still working as well as it could? What improvements can be made? What do you know today about how people use your awesome application, that you didn't know 6 months ago? Use this time to think forward. You have something that is already addressing current use cases. But what about the future? You have the chance right now to think about what could be. How cool is that?!?! Make the product better, more robust, able to make gold out of frustrated, tired developers. I don't care, but think about it. You could forever be enshrined in the company's legacy as the engineer who undertook a wondrous experiment and had it pay dividends in the end. Look at you, you immortal demigod. Way to go.
Mull it over and get back to me.
Published at DZone with permission of Ross Garrett, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
The SPACE Framework for Developer Productivity
Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
Database Integration Tests With Spring Boot and Testcontainers