What are Microservices? Microservices Examples
Tags: microservices, monolithic, devops, database
Published: 2021-01-23 12:46:46

Developers use microservices to build scalable and functional applications piece by piece. Such architectures help deliver a more complex app structure without trying to create all at once.
<h2>What are Microservices?</h2>
Microservices are the parts of an SOA (Service-Oriented Application). They are small service units that work independently. With the special approach in software engineering, developers break the app into separate sectors that have individual structure and even code language. Each accomplishes the single business goal, uses unique data storage methods and owns a different interface.
<h2>Microservices vs Monolithic Architecture</h2>
<img class="alignnone wp-image-12191" src="https://www.romexsoft.com/wp-content/uploads/2020/10/monolith_1-monolith-microservices.png" alt="monolith microservices" width="900" height="552" />

Image Source: <a href="https://aws.amazon.com/ru/microservices/">AWS</a>

A traditional monolithic application is the opposite of microservices architecture. It is a <i>single</i> software unit where all the components are interdependent. The database of this architecture serves for the whole stack. The development process is slow, yet simple. In comparison with microservices, monolithic architecture doesn’t require expert knowledge and allows to build the app from scratch.

However, if you aim to launch a complex application with a wide operational system, then microservices will do the work better. Here is why:
<table>
<tbody>
<tr>
<td><b>Monolithic architecture</b></td>
<td><b>Microservices architecture</b></td>
</tr>
<tr>
<td>The whole structure works for all the goals</td>
<td>Each unit accomplishes ONE business goal</td>
</tr>
<tr>
<td>The disaster affects the whole app</td>
<td>If the fault happens, it only impacts a single unit which is easy to rebuild and redeploy</td>
</tr>
<tr>
<td>There is only one data model and technology for the structure</td>
<td>Federated data allows choosing the best-suited model for each app process</td>
</tr>
<tr>
<td>Slow development process</td>
<td>Due to small teams that lead each microservice, the development is quicker and more efficient</td>
</tr>
<tr>
<td>Unflexible resource allocation</td>
<td>Depending on which service customers use the most (for example, the product listing), developers understand which unit requires more resources</td>
</tr>
</tbody>
</table>
<h2>Microservice Cons</h2>
As you are aware of the microservice benefits, let’s explore some of its drawbacks. Here are some of them:
<ol>
 	<li style="font-weight: 400;">Since microservice runs as a complex system, you need to establish communication between all the units, which requires additional effort;</li>
 	<li style="font-weight: 400;">It is hard to manage and test independently deployable structures;</li>
 	<li style="font-weight: 400;">The maintenance of each unit requires money and good teamwork;</li>
 	<li style="font-weight: 400;">Because of the different programming languages, there are more services to look after;</li>
 	<li style="font-weight: 400;">The processing and storage of the unstructured data is a challenge because of the separate mechanisms.</li>
</ol>
<h2>Typical Microservice Architecture</h2>
There are several approaches to building communication between microservices and users. One of them is a <i>direct connection.</i>

<img class="alignnone wp-image-12192 size-full" src="https://www.romexsoft.com/wp-content/uploads/2020/10/direct-client-to-microservice-communication.png" alt="direct client to microservice communication" width="918" height="537" />

Image Source: <a href="https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-container-applications/direct-client-to-microservice-communication-versus-the-api-gateway-pattern">Microsoft</a>

Such a plan suits small apps with minimum functionality. Since the client app is directly connected with each microservice, it’s better to cut the numbers of endpoint consumption for the sake of convenient UI, easy authorization and security.

The alternative to direct communication is the API gateway implementation. It is the better option for your app if it copes with many microservices.

API is sometimes called back-end for front-end. The gateway routes requests from users to microservices. If you establish a single gateway for all the microservices, it will work as a monolithic aggregator. There are some threats, as the gateway may become bigger and overloaded with tasks. So, it would be useful to split the API into different gateways, with individual facades for client needs.

<img class="alignnone wp-image-12193 size-large" src="https://www.romexsoft.com/wp-content/uploads/2020/10/custom-service-api-gateway-1024x594.png" alt="custom service api gateway" width="1024" height="594" />

Image Source: <a href="https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-container-applications/direct-client-to-microservice-communication-versus-the-api-gateway-pattern">Microsoft</a>

As you can see from the picture, the mobile app and the web app are separated. There are special facades for each of them due to different requirements for data compression and optimization.
<h2>What Are Microservices in AWS</h2>
AWS offers many services for developing successful microservice architecture. The typical case is shown on the scheme below.

<img class="alignnone wp-image-12195 size-full" src="https://www.romexsoft.com/wp-content/uploads/2020/10/typical-microservices-application-on-aws.jpg" alt="What Are Microservices in AWS" width="545" height="385" />

Image Source: <a href="https://d1.awsstatic.com/whitepapers/microservices-on-aws.pdf">AWS</a>
<h3>1. User Interface</h3>
AWS uses <a href="https://aws.amazon.com/s3/">Amazon Simple Storage Service</a> and <a href="https://aws.amazon.com/cloudfront/">CloudFront</a> to deliver the static web content. You can benefit from reduced latency level due to the convenience of edge locations. Users are served from the nearest ones.

For further information, visit our blog: <a href="https://www.romexsoft.com/blog/simplifying-cloud-storage-costs-how-aws-s3-pricing-work/">Simplifying Cloud Storage Costs: How AWS S3 Pricing Work</a>
<h3>2. Microservices</h3>
AWS pays attention to the API, especially RESTful web services API. Apart from the connection between client and server, it has additional features as traffic management, authentication, authorization.

For the microservice implementation, you may use <a href="https://aws.amazon.com/lambda/">AWS Lambda </a>and <a href="https://aws.amazon.com/fargate/">AWS Fargate</a>.
<h3>3. Data Store</h3>
AWS offers the<a href="https://aws.amazon.com/elasticache/"> Amazon ElastiCache</a> as a managed service for storing data which is needed for microservices. The service works as a cache, controls the load balancing and the latency level.

<a href="https://aws.amazon.com/dynamodb/">Dynamo DB</a> is a document database with the opportunity to retrieve and store data. It can process 10 trillion requests per day.

<a href="https://aws.amazon.com/rds/aurora/">Amazon Aurora</a> is a relational database constructed for a cloud. It works 5 times faster than MySQL and saves costs, providing the same reliability. The service sends data copies to several regions to ensure security and fast disaster recovery.
<h2>Use Cases: Uber</h2>
Since the microservice architecture is a distributed system, where all the units are deployed independently, it is very useful for e-commerce. For instance, if you are running the online store, and the payment system requires the update then you can change only that part, without touching the rest of the system.

A few years ago, nobody even knew about microservices, but now many big companies benefit from it, and Uber isn’t an exception.

In the beginning, Uber started as a monolithic architecture. It was enough for the small enterprise, located in one city. With the worldwide growth, the program needed to be scaled, new features had been added, and it became quite a problem to maintain all of that as a monolith.

To avoid risks and hardships while updating and fixing bugs, Uber decided to build the microservice architecture.

<img class="alignnone wp-image-12196 size-full" src="https://www.romexsoft.com/wp-content/uploads/2020/10/Microservice-Architecture-Of-UBER-Microservice-Architecture-Edureka-768x762-1.png" alt="Microservice Architecture Uber" width="768" height="762" />

Image Source: <a href="https://dzone.com/articles/microservice-architecture-learn-build-and-deploy-a">DZone</a>

As you can see, each process has a separate unit in the system. Drivers and passengers are connected through the API Gateway, the service dependencies were broken, and each unit can be scaled independently.
<h2>Conclusion</h2>
As you may have understood, there is no one great solution for all of the companies. Choose the traditional monolithic structure for the small enterprise, keep the microservices for big boys with many operations. Keep in mind, that monolith requires a constant rebuild of the whole code base, whereas microservice units can be scaled independently.

You may also be interested in: <a href="https://www.romexsoft.com/blog/10-ways-to-reduce-your-aws-bill/">10 Ways to Reduce your AWS Bill</a>

Original article:<a href="https://www.romexsoft.com/blog/what-are-microservices/">https://www.romexsoft.com/blog/what-are-microservices/</a>