Why HTTP is a wrong choice for Microservices??

Hashir Muhammadh
4 min readAug 31, 2022

--

Microservice is what exactly is an architectural style that develops a single application as a set of small services. “we isolate bounded context to each services”. This is the main fundamental of microservices.

Before we jump into our topic directly you need to know about simply what is Microservices. I hope you have enough of knowledge.

Let’s jump into our topic I’ll explain with examples…..

When you requesting a new connection to the network providers they will verify the particular customer has more connections or services that are you already using TV connection , fixed line, 4G connections and something like that. If you are use those things did you pay the bill well, are you a blacklisted customer, are you a outstanding with us or sometime they need to check with other providers is he a blacklisted user whether the government banned to use mobile phone something like that the provider need to verify.

They have a branches or sections to handle different product or services

They have a separate services to handle every sections.

every particular customer has unique ID to identify the customer. So the new connection service request to the TV service whether the customer recommended or has an issue, then the particular service will reply their response. So can send request parallelly to every service and they will reply their response to new connection service. If every service responded that the customer profile is perfect and he will get a new connection.

The problem is above database tables are in different databases handle by different sections.

when the data insert into the database if one database not successfully saved it is not easy to roll back others. This is distributed transaction problem.

Let’s assume using http backend for all things. here can send all the request at the same time. The new connection service sending the request to save the new connection to all those services.

At this scenario some problems may occur that are:

  • The 4G service is offline
  • Other provider service is getting slow transactions

If you need to activate the new connection you need to get response from the 4G service. But that is in offline. So you cannot.

Other case is there are 100 requests are happen in the same time those are done by all other services except “Other provider ” service. those requested are waiting until the last response come. This call Cascad Failures.

Cascad failure: If A wants to finish their work B needs to be finish first and If B needs to complete their work C need to complete first. If C fails B and A also fail.

Now the insert process is not complete, it’s still on progress…

Another scenario is …

http is synchronous protocol

When the PO (purchase order service) sending 500 requests to item service it will get the response from the item service. Since http works as a synchronous mood. Open a connection and fire up the requests and the response come in a order by you sends the request.

So if R1 gets response in 10ms then R2 needs 100ms and R3 wants 1ms the response will come by request order. Even R3 wants 1ms it must wait for the the other two requests. since http is synchronous protocol doesn’t matter what you are using asynchronous manner.it doesn’t work.

So these are the real world scenarios and problems against using http in microservices.

What is the solution for this??

Instead of HTTP, programmers can implement messaging services. Kafka is one of the best messaging framework.

Now verification requests are not sent directly to other services. Request sending to Kafka. All services listening to Kafka. When a request is received they collect it. after processing they send a response back to Kafka. Using Kafka, the system can work asynchronously. So one request is not depending on another request. The system will not be blocked due to the slowness of getting responses. Using the messaging framework we can get a solution for those problems.

--

--