Kafka Msg VS REST Calls

Gist (for those who want just the gist)

  1. Kafka – Publish & Subscribe (just process the pipeline, will notify once the job is done)

    REST – Request & Await response (on-demand)


  1. Kafka – Publish once – Subscribe n times (by n components).

    REST – Request once, get the response once. Deal over.


  1. Kafka – Data is stored in topic. Seek back & forth (offsets) whenever you want till the topic is retained.

    REST – Once the response is over, it is over. Manually employ a database to store the processed data.


  1. Kafka – Split the processing, have intermediate data stored in intermediate topics (for speed and fault-tolerance)

    REST – Take the data, process it all at once OR if you wish to break it down, don’t forget to take care of your OWN intermediate data stores.


  1. Kafka – The one who makes the request typically is not interested in a response (except the response that if the message is sent)

    REST – I am making the request means I typically expect a response (not just a response that you have received the request, but something that is meaningful to me, some computed result for example!)

Q&A style

Is your data streaming?

If the data keeps on coming and you have a pipeline to execute, Kafka is best.

Do you need a request-response model?

If the user requests for something and he awaits a response, then REST is best.

Kafka (or any other streaming platform) is typically used for pipelines i.e where we have forward flowof data.

Data comes to Kafka and from there it goes through component1, component2 and so on and finally (typically) lands in a database.

To get the information on-demand we need a data store (a database) where we can query and get it. In such a case we provide a REST interface which the user can invoke and get the data he wants.


Regarding your example,

Everyday vendor service calls the vendor API to get new items and these need to be moved into inventory service

Questions & Answers

Is your vendor API using REST?

Then you need to pull the data and push to Kafka. From there your inventory service (or any other service thereafter) will subscribe to that topic and execute their processing logic.

The advantage here is that you can add any other service which requires vendor data as a consumer to the vendor topic.

Moreover, the vendor data is always there for you even after your inventory service processed it.

If you use REST for this, you need to call the Vendor API for every component that requires vendor data which becomes trivial when used with Kafka

Do you want the inventory to be queried?

Store it in a database after processing through Kafka and provide a REST on top of this. This is needed because Kafka is typically a log, to make the data query-able you would need some database.

From stackoverflow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.