We are talking about microservices. It is a pattern to resolve the complexity of the system those need to process a high amount of data within a short period.
Financial lose may occur on implementation of this pattern for an application of limited complexity in the initial phase. Initial phases have a learning curve to understand the relation and behavior of domain entities.
Small and medium companies lean this during development. Large companies can allocate additional times for documentation and correction on design phases for a reasonable long period. So, sometimes it is good to start with a monolithic architecture and grow with the achievement of the company then migrate to microservices.
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Introduction to requirement of microservices
1. INTRODUCTION TO
THE REQUIREMENT OF MICROSERVICES
Presented by:
Avik Das
Software Developer
Here is a presentation for those
developers who are thinking about
getting benefited using
microservices.
Microservices is a pattern of
implementing solutions for
complex problems. Whereas, it
has complexity in implementation.
We can ignore this pattern as long
as we have the option to go with
the monolithic architecture
pattern.
2. Example
Bulk Billing System
It is good to start with an example
of a common problem.
A news magazine publishing house
generate bills for their customers
on the first day of every month
and delivers as a PDF attachment
of the email.
3. Activities
First, they calculate the charges
based on usage recorded in the
database.
Then, PDF files are generated
based on an existing template
merged with calculated data.
The system sends SMS to
customers to notify the billing
amount and due date.
Finally, the system uploads all PDF
files to the server of the vendor,
who is responsible for printing the
hard copy and do the delivery by
postal services.
Calculate Charges
Generate PDF &
Send Email
Fetch Records
End of
Records
Send SMS
Upload for
Printing
Select Record
1st of
every month
Run schedule
4. Initial days
Let's assume that initially, the
publishing house has 1000
consumers only and have a small
budget to implement the
automation.
We can create a single service to
process the task in a web server
without any complexity.
Server instances with 1 CPU and 2
GB RAM should be available in low
budget, which is going to be
enough for computation of the
above process in an average time.
A standard shared hosting
environment can provide this kind
of a similar infrastructure too.
ASP.net / JAVA / PHP
application
Database
Web Server (IIS / Apache / Tomcat) File Server
Cron Job / Schedular
SMS Gateway
Email Gateway
1 CPU (2.5 GHz) | 2 GB RAM
5. Complexity begin
After six months, the company
achieve massive success and
enrolled 1,00,000 customers. Now
the system starts producing delays
in processing. Several in-memory
processes getting failed due to
limitation of memory.
We have to use a more powerful
CPU for a single-threaded process.
So, we have to replace the CPU
and increase RAM.
Shared hosting has a limitation on
increase resources. We have to
move the application to a different
server or go for cloud instances
like AWS EC2 or Azure VM.
ASP.net / JAVA / PHP
application
Database
Web Server (IIS / Apache / Tomcat) File Server
Cron Job / Schedular
SMS Gateway
Email Gateway
1 CPU (3 GHz) | 4 GB RAM
6. Application crashed
After two years of exclusive services,
they earned 1 million customers.
Now, we can suggest for following
solutions
1. Process bills in multiple batches
2. Get the benefits of parallel
processing over multiple CPUs
3. Run multiple instances of the
same application to execute
different batches.
The above solutions require changes
in the script. Whereas, dependencies
on third-party gateways or services
may introduce accidental complexity.
E.g. an email gateway supports only
100 requests per minutes, and a
single application can generate 1000
bills per minutes.
App
Database
Web Server (IIS / Apache / Tomcat) File Server
Cron Job / Schedular
SMS Gateway
Email Gateway
2 CPU (2.5 GHz) | 8 GB RAM
App
7. Alternative approach
So, we have to implement different
services for four tasks of the
process. Services will be
independent and capable enough to
manage internal or external
complexity without affecting the
execution of other services.
These services will have schedulers
to run and execute the scripts
according to available data in the
databases and limitation on every
iteration.
Billing service will have primary
data for calculation and initiate the
process for other services. But, how
it will communicate with other
services when these are deployed
in separate servers.
File Server
SMS Gateway
Email Gateway
Server
Scheduler (Every day)
Billing Service
Database
Server
Scheduler (Every minute)
PDF Generator &
Email Service
Database
Server
Scheduler (Every minute)
File Uploading
Service
Database
Server
Scheduler (Every minute)
SMS Service
Database
8. APIs
Application Programming Interface
is a good suggestion to interact
across multiple programs. Here we
can deploy APIs into the server of
services. These will be available for
billing service to push data into
respective databases.
Now we can use different type of
resources for different services.
Services may use multiple CPUs and
memory as per requirement.
These services focused on a small
part of entire process, that's why
we called them microservices.
Microservices are implemented for
more complex problems to be
resolve, which we can discuss on
case to case basic.
Server
Scheduler (Every day)
Billing Service
Database
Server
Scheduler (Every minute)
PDF Generator &
Email Service
Database
Server
Scheduler (Every minute)
File Uploading
Service
Database
Server
Scheduler (Every minute)
SMS Service
Database
API API
API
2 CPU (2.5 GHz) | 4 GB RAM 1 CPU (2.5 GHz) | 2 GB RAM
1 CPU (2.5 GHz) | 8 GB RAM1 CPU (2.5 GHz) | 1 GB RAM
9. Challenges
Microservices suggest for
1.Separate code bases for services
2.Separate configuration files
3.Advance deployment tools
4.Propper integration testing
5.Monitoring through dashboard
Process to set up the entire pipeline
for managing microservices is a very
critical process; after we finish the
design for how to split the tasks into
multiple services.
Cyclic dependencies on services
might be the worst accidental
complexity of any microservices
eco-system.
Cost of development and managing
infrastructure going to be high for
an initial start-up venture.
Code Base
Database Schema
Settings &
Configuration
Code Base
Database Schema
Settings &
Configuration
Code Base
Database Schema
Settings &
Configuration
Developer Developer Developer
Version Controlling, Testing, Monitoring & Deployment Tools
10. Advantages
We can practice the single
responsibility principle while
working with monolithic
architecture pattern. It helps us to
create boundaries in our code
blocks for classes with minimum
dependencies or loosely coupled
coding.
Most of the renowned companies
migrated from monolithic systems
to microservices. Having a good
quality of codebase can reduce the
time of migration.
Advantages in microservices pattern
1. Improve performance
2. High scalability
3. Flexibility of technology
selection
4. Cross-functional team
5. Improved fault isolation
6. Faster deployment
Service Instance #1
SQL Server Database
Load Balancer
Service Instance #1
Service Instance #2
MySQL Database
Service Instance #1
Mongo Database
Oracle Database
C#
Developer
PHP
Developer
JAVA
Developer
Kubernetes, Docker Tools