What is a Micro-service? ๐ค
A Micro-service is a pattern for organising computer systems into services that can scale with demand.
They're usually small, independently deployable units of software that is part of a larger application or system.
The micro-service is split into sections that all deal with their own individual processes.
Each section has a specific purpose that addresses a requirement to be fulfilled within the system the micro service is implemented on.
Think of a Micro-services to software as what factories are to manufacturing
Instead of having one person/machine build an entire car by itself, each area of the car is built by an individual/machine that is catered to building that part. ๐ฌ๐ฌ๐ฌ
An example of a real world micro-service is the recommendation system used by Netflix.
The system uses the users:
Preferences
Viewing history
Liked content
etc...
And generates content that the user may like based on the available data.
So here's how it works:
The recommendation micro-service receives data about the users interactions through the movies or shows they rate, like or add to their list.
The micro-service process the data by applying algorithms and machine learning models to create personalised recommendations for the user.
Because the micro-service operates on its own independent method, it can be scaled on demand meaning when more users are simultaneously running the Netflix app, additional instances of the recommendation service can be deployed to handle the increased load.
If there are issues with the recommendation service such as high latency, this won't necessarily affect the application as whole. For example other micro-services like the user account management will still work as normal.
Before Micro-services ๐ต
Note: the word "monolithic" means all in one.
Before micro services were a thing, applications were built in a monolithic approach.
The application was broken into 3 separate sections of an application:
Front-end: What the user can see and interact with ๐
Business logic: The code that decides how the data retrieved from the data storage will be shown to the user on the front-end. ๐ผ
Data storage: This is where the business data is stored ๐ฆ
There are a handful of issues with the monolithic approach:
Scaling up ๐ช
Scaling up systems with more features like this can have major issues such as entire systems needing to be scaled up or down as required.
Meaning this can lead to inefficient resource usage and difficulties in handling sudden spikes in traffic.
This can result in the application crashing and cause widespread blackouts.
With Micro-services, scaling up is a simple as scaling up individual services rather than the entire application.
Companies like Netflix, Uber and Spotify have all migrated to a micro-service method due benefits regarding to scalability.
Slow performance ๐
It's inefficient, although it performs well for small applications, it's not a suitable measure for large ones.
A single point in failure any point of the system can bring down the entire whole system. Causing massive issues regarding the business aspects.
Availability ๐ป
If a single server fails in a monolithic method, the entire application either crashes or stops responding.
In addition to this when the system is at peak periods, it falls into a non responsive mode or slows down considerably.
With micro-services, if a single service fails, the application doesn't crash rather it continues to function as normal until the services is retrieved or dealt with gracefully.
When should you apply the monolithic approach?
The monolithic approach is perfect for building small scale applications.
Why?
Because, they're straightforward to build, test, deploy and debug.
Instances of when to apply it?
Your in a small team during the founding stage: ๐งโโ๏ธ
A team with 2 - 5 members don't need to deal with the complexities of the micro-services method.
The monolith method can deal will all of the business requirements allowing you to give more attention to your business needs rather than the technology you use.
Building a simple application with an expected scale and complexity ๐
If you're creating a simple application that doesn't require complex business logic and the need to have incredibly scalable nor flexible functionality, then it best to go with the monolithic method!
Proof of concept ๐
Especially if you're in a rush to build a working product, avoiding the complexity of micro-services allows you to bring your idea to life as quick as possible and with time you can pivot and refactor on the choice of architecture later down the timeline.
The monolithic approach should NOT be used when โ:
The application is expect to grow significantly over time and the requirements require it to scale. Especially due to increased traffic.
The application needs are complex and diverse in terms of functional requirements and could be better served by being divided into smaller, manageable components.
The application needs a high level of availability and needs to minimises the downtown during deployments and updates.
External Links:
https://www.techaheadcorp.com/blog/design-of-microservices-architecture-at-netflix/