Reputation: 7514
I am exploring micorservices architecture through books, blogs etc.
What I have seen is that mostly people implement microservices using REST. Isn't it contradictory?
Microservices are supposed to decouple services to achieve scalability, but REST communication protocol is synchronous.
So how can these two go together?
Upvotes: 0
Views: 614
Reputation: 1159
I'm assuming you are looking at the linking of multiple HTTP Restful services.
If you are designing the messaging architecture for a Restful set of microservices. You need to take into account the risk and benefits of each communication technology. Remember you don't have to use one, you can use the best tool for each job.
The most common seemingly are HTTP and AMQP (Advanced Message Queuing Protocol). They both serve different purposes.
If you are providing the back end to a website as micro services. Then chaining calls together in a synchronous fashion might be required, if the user requires a response from the website. Also it's likely your inbound requests will be HTTP at this point.
Alternatively if no response is required, you might want to consider fire and forget messaging queues. These would allow messages to be passed to other micro-services asynchronously.
There is a great e-book that covers this topic in great detail. https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/ [.NET Microservices. Architecture for Containerized .NET Applications]
This page covers the exact topic you are discussing. https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/architect-microservice-container-applications/communication-in-microservice-architecture [Communication in a microservice architecture]
Upvotes: 1
Reputation: 57297
The REST interface is designed to be efficient for large-grain hypermedia data transfer, optimizing for the common case of the Web, but resulting in an interface that is not optimal for other forms of architectural interaction. -- Roy Fielding, 2000
"REST communication protocol is synchronous."
That's not quite right, on a couple of levels.
First, there is no "REST communication protocol"; REST is an architectural style.
Hypertext Transport Protocol, aka HTTP, is a an application protocol for for hypertext information systems. REST is an architectural style, the web is the reference implementation.
Second, HTTP isn't actually synchronous. Because there are no generic correlation identifiers in the metadata of the request, the client needs to keep track of the order in which requests were sent along a given connection. See RFC 7230, Section 5.6. It's "just" messaging.
Apache's HttpCore Tutorial includes a discussion of non-blocking HTTP connections.
Upvotes: 1