DEV Community

ujwal dhakal
ujwal dhakal

Posted on

Why do we microservice?

Well Microservice word itself explains micro + service which is the breaking
down of services into individual independent one. It's an architectural pattern
on designing the system and its flow.

But why do we need to microservice? Well let me explain with an example

Let's say someone wants to build an eCommerce application for a single country
with no shipping. Initially, he wants to launch eCommerce store with limited
100+ products only with, stripe & cash on delivery payment method. He wants to
build an eCommerce app so fast with less money & time so that he wants to know
whether this business idea is going to work or not.

Note that resources are limited Time, Money, Quality. If you focus on quality
you need more money and time. If you want to finish in less time with less
money, the quality will be less.

After 1 month of hard-working eCommerce, the app was ready where people could
buy listed products with limited payment gateway for a single country. The
developer has made an application keeping in mind that the site will only handle
1000 users per second or less than 1000 users since the owner wanted to build
his MVP so fast. Now the eCommerce seems booming, each and every people are
loving this idea and using in their daily life. Now more people using means more
traffic means your limited computing resource has to serve many people now. As
this business is booming now the owner wants to build further, he wants to make
it global with a variety of payment gateways, shipping, inventory management to
work on. As the traffic starts to increases-:

  1. The site seems extremely slow people had to wait for more time to choose products.
  2. Adding a new payment gateway, shipping method etc was taking so much time.
  3. A bug in one feature was taking a whole system down which was reported by the customer.
  4. Deploying was taking so much time than it used to.
  5. The server was from the US region and people from Asia are facing some latency issues.
  6. Since they were using PHP everywhere and they wanted to use languages like go, the node for concurrency, parallelism for more efficient computation. But it was difficult for them to implement a new stack.

Now he wants his tech team to solve these problems and tech team has one thing
in mind, an idea of restructuring them into microservices (Product listing
service, payment service, order processing service, inventory management
service, Automation testing service, etc) and after they have successfully
implemented microservices

  1. Scaling site was easy for them they could rewrite site into the latest stack.
  2. Adding a new payment gateway, shipping method, features was easy for them as code base was splitted it was easy for multiple developers to work autonomously.
  3. Now a downtime of one service won't affect the downtime of others
  4. Deploying was so much easier for them as they had used Kubernetes/ EKS and they could easily deploy/revert specific services they have worked on
  5. Due to their flexibility, they were able to implement dedicated DevOps for multi-region network serve and they have been implementing Kubernetes and scaling their services according to traffic.
  6. Now their frontend relies on on react js, whereas they have been using PHP for some for product listed & checkout. Where was order processing was done by Golang leveraging concurrency and they have been using cypress for UI Automation

Like everything comes off with tradeoff surely microservice is no different it
has its own tradeoffs like the specialized team to handle multiple services,
hard to trace / monitor, hard to maintain consistency, etc which I will describe
in a future post. So decide which one will you really need. Happy Coding!

Top comments (0)