Exploring Microservices Architecture: What You Need to Know
Tags: microservices
Published: 2019-07-24 13:44:25

Microservice Architecture (a.k.a. “Microservices”) is a method of developing software focused on building single-function modules. The term was <a href="https://en.wikipedia.org/wiki/Microservices#Introduction">coined in 2011</a> and the microservice approach quickly gained steam near the end of 2013:

<a href="https://trends.google.com/trends/explore?date=2011-06-12%202019-07-12&amp;geo=US&amp;q=microservices"><img class="lazy aligncenter wp-image-20384 size-large" src="https://pagely.com/wp-content/uploads/2019/07/microservices-popularity-time-1110x394.png" alt="Growth in microservices popularity" width="730" height="259" /></a>

The advancement of microservices was driven, in part, by tech giants like Netflix, Amazon, Twitter, Google, and Uber evangelizing its benefits.
<h2>What’s all the microservice buzz about?</h2>
Why is anyone interested in microservices? To answer that question we need to briefly explore the evolution of software architecture.
<h3>Monoliths</h3>
Not long ago, most software was “monolithic.” A monolithic design means the user interface and the data access code are combined into a single, self-contained program.

Monolithic software design comes with some downsides. Most notably, because of the self-contained, interdependent nature of monoliths, a failure anywhere in a program can cause the whole application to come crashing down. And, there are other issues:
<ul>
 	<li><strong>Reduced agility.</strong> The application’s codebase is released all at once. Developers need to code and deploy the entire stack. Rebuilding the whole application takes time and slows down the pace at which new features can be delivered.</li>
 	<li><strong>Complexity.</strong> Large applications become harder to understand and work with. There are side effects of changes that might not be obvious due to easy-to-overlook dependencies leading to “mysteries and magic” that can be difficult to untangle.</li>
 	<li><strong>Less scalability.</strong> Scaling becomes a matter of adding new instances to run the entire codebase rather than adding instances to scale individual pieces of the app that might be used more than others. Unequal usage of that application can lead to some resources being wasted and other resources straining the server.</li>
</ul>
<h3>Service-Oriented Architecture</h3>
To overcome these problems, a <a href="https://en.wikipedia.org/wiki/Service-oriented_architecture">Service Oriented Architecture</a> (SOA) was introduced and became popular in the early and mid-2000s. The SOA views an application as a collection of connected services running in parallel. Each service is self-contained and represents a specific business activity with a desired outcome.

This approach helps solve many of the downsides inherent to monolithic software designs:
<ul>
 	<li><strong>Easy maintenance.</strong> Distinct services can be updated without affecting other services.</li>
 	<li><strong>Platform independence.</strong> You can create an application by combining services that use different solutions.</li>
 	<li><strong>Improved <a href="https://pagely.com/blog/wordpress-data-reliability/">reliability</a>.</strong> It is easier to locate the problem and debug a small service than it is with a monolith <span style="font-weight: 400;">and a single service going down usually won’t take down the entire application. </span></li>
 	<li><strong>Scalability.</strong> Individual services can scale by adding server resources as demand increases.</li>
</ul>
The Microservice Architecture (MSA) is a variant of SOA. In fact, some people argue that MSA and SOA are not really different things at all, so the term “microservices” is superfluous. Nevertheless, the term seems to be here to stay.
<h2>What are microservices?</h2>
<a href="https://www.quora.com/What-are-the-alternatives-to-microservices/answer/Jerry-Andrews?ch=10&amp;share=47420578&amp;srid=QhZeq">According to Jerry Andrews</a>, when people talk about MSA they’re generally referring to software design that includes these characteristics:
<ul>
 	<li>Services typically rely on other services to accomplish their goals</li>
 	<li>Services are <a href="https://cloud.google.com/containers/">containerized</a></li>
 	<li>Asynchronous communication is handled via messaging or job queues and synchronous communication is handled via HTTP with JSON messages</li>
 	<li>Instance management automation</li>
 	<li>Auto-scaling components</li>
</ul>
There is some debate on the exact definition and some would argue with aspects of the defining characteristics repeated here.

SOA and MSA are also differentiated by how granular services are:

<a href="https://dzone.com/articles/microservices-vs-soa-whats-the-difference"><img class="lazy aligncenter wp-image-20386 size-large" src="https://pagely.com/wp-content/uploads/2019/07/monolith-soa-microservices-granularity-1110x708.png" alt="Service Granulariity of Monoliths vs SOA vs Microservicess" width="730" height="466" /></a>
<p style="text-align: center;"><em>Source:</em> <a href="https://dzone.com/articles/microservices-vs-soa-whats-the-difference">Dzone</a></p>
There are also differences in how individual services are conceptualized. SOAs view services through distinct lenses:
<ul>
 	<li>Business services</li>
 	<li>Enterprise services</li>
 	<li>Application services</li>
 	<li>Infrastructure services</li>
</ul>
In contrast, MSA views services purely as functional (without viewing them through the separate lenses SOA does). Microservices might be created for discrete functional services like:
<ul>
 	<li>Authentication</li>
 	<li>Email sending</li>
 	<li>Account management</li>
 	<li>Account creation</li>
 	<li>Billing</li>
 	<li>Messaging</li>
</ul>
<h2>Benefits of Microservices</h2>
The self-contained nature of individual microservices introduces <a href="https://skelia.com/articles/5-major-benefits-microservice-architecture/">a variety of benefits</a>:
<ul>
 	<li><strong>Simplicity.</strong> Microservice architectures are usually more simple so they can be easier to build and maintain.</li>
 	<li><strong>Autonomous cross-functional teams.</strong> Technical decisions can be made faster and by smaller groups.</li>
 	<li><strong>Flexibility in technology.</strong> Like the SOA approach, microservices allow a blend of solutions to work together.</li>
 	<li><strong>Flexibility in <a href="https://pagely.com/kb/en/what-is-horizontal-scaling/">scalability</a>.</strong> Microservices can scale independently so additional resources can be added exactly where they’re necessary.</li>
 	<li><strong>Code can be re-used.</strong> For example, here at <a href="https://pagely.com">Pagely</a> we were able to use some Pagely-made microservices to power our new serverless hosting solution, <a href="https://northstack.com">NorthStack</a>.</li>
</ul>
<p style="text-align: left; padding-left: 40px;"><em>Source:</em> <a href="https://skelia.com/articles/5-major-benefits-microservice-architecture/">Skelia</a></p>

<h2>The downsides of microservices</h2>
While many companies are refactoring their monoliths in favor of a microservices approach, microservices aren’t always the right answer. It’s not the one true perfect way to design an application that everyone should always use. In many cases, the upsides of MSA outweigh the downsides, but sometimes not because:
<ul>
 	<li><strong>Microservices can introduce complexity.</strong> A monolith’s complexity comes from how challenging it can be to understand how different code interacts, MSA’s complexity comes from having more and more of the code split out into individual services. Five or six services aren’t difficult to manage, but twenty, thirty, or more can be!</li>
 	<li><strong>Microservices require changes to culture and process.</strong> Companies that adopt microservices will need to adopt an agile coding approach and, often, create a DevOps team.</li>
 	<li><strong>Microservices can be costly.</strong> Network calls aren’t free and add up. In addition, the labor costs of breaking up a monolith can create an otherwise unnecessary expense.</li>
 	<li><strong>Microservices may introduce security issues.</strong> Each inter-network communication path creates a new security risk that needs to be addressed and monitored.</li>
</ul>
<p style="padding-left: 40px;"><em>Source:</em> <a href="https://www.tiempodev.com/blog/disadvantages-of-a-microservices-architecture/">Tiempo Development</a></p>

<h2>Moving from monolith to microservices</h2>
Many applications begin their lives as monoliths but as they mature, bottlenecks that should be split out into microservices become apparent. This refactoring process is known as “breaking up the monolith.” The two architecture approaches are not an “either-or” thing or a “right or wrong” thing— many popular apps are a monolith-microservices hybrid.
<h2>Starting from scratch: Monolithic versus Microservice architecture</h2>
While microservices offer distinct advantages over monoliths, building software from scratch as a monolith and then moving toward a microservice approach may sometimes make more sense:
<ul>
 	<li>Developing an application as microservices will usually be slower (initially) than taking a monolith approach</li>
 	<li>As the monolithic software matures and the big picture becomes more clear, the functions that should be split out into microservices will be more obvious.</li>
 	<li>A well-designed monolith can easily be broken out into microservices later.</li>
</ul>
If development time is a non-issue, taking a microservices approach from the beginning avoids the effort and expense of later refactoring. You could weigh the pros and cons of absorbing the time costs of starting with microservices versus delaying those costs and beginning with a monolith. The right answer will depend on the priorities of the company and its project.