What is difference between event driven and REST API?
I think event driven solutions are the next step in the evolution of efficiently communicating between different microservices.
While REST can have its advantages (say for something like authentication where you only move forward once you get a synchronous response from the server), event based communication wins in almost every scenario.
This is because the nature of how applications communicate is changing. Gone are the days where services follow the request/response model. Today it's all about consuming millions of events as applications scale...
Think about Uber. What if every single car on the road was abiding by the request/response model. That would lead to so many unnecessary requests to the Uber server(s) and result in a massive performance hit.
Since everyone wants the solution they build/architect to ultimately be adopted on a wide scale (don't argue with this point because I totally understand that you can ..but let's be honest unless you are building an internal UI dashboard for some shit company then you want people using whatever you build) they want to efficiently handle millions of events / changes in state to register in a scalable fashion.
This is why event driven architecture wins 99.9999% of the time in modern day software engineering.
REST = sync
Event = async
While REStful APIs can achieve asynchronous communication, an event based solution is much better for communicating in an async fashion. The main issue with event driven API is that there are more centralized points of failure. AKA if you are using Kafka and Kafka goes down...well you are out of luck.
Conversely with a REST API, if the calling service is down then you just get a 503 or some response indicating the service is not available. You can simply try again later.
In event driven architecture, failed messages are backed up in a queue or topic. When things come back online then everything gets processed...
REST is a thing of the past. No one wants to wait for a response from a server anymore.
REST sucks. Events don't :)
async vs sync basically...
Ron Shepard |
An event driven system is characterized by a pub/sub or producer/consumer model whereas REST is request response.
An event driven system is asynchronous. A REST API is synchronous.
An event driven system tends to take a "fire and forget" approach to sending information downstream or to other mircorservices. A REST API waits for a response from another service before making a decision (kind of redundant when thinking async vs sync).
An event driven system tends to be more resilient to failures and can be more independently scaled.
An event driven solution is better for asynchronous activity whereas a REST based solution is better for situations where a client needs to wait for a response (such as authentication).