Suppose there is a microservice that has an restful HTTP API for CRUD operations on a database - nothing fancy, but there is a journal table of all changes recorded for audit purposes. Suppose also there is an event bus (in my case Kafka, but could be anything) to which data change events must be published.

The journal table has sufficient information to create all events.

The options on the table are:

  1. Microservice publishes its own events
  2. Another application publishes events based on polling the journal table

Both options guarantee that all events will (eventually) be published, and have similar performance and similar, simple design complexity both approaches will be 100% robust.

Things to consider, which may or may not affect the answer:

  • performance is similar, and largely irrelevant anyway
  • while the journal table is not expected to change, option 2 means having a foreign application depending on it thus creating an API/SLA that is tightly coupled to an implementation choice (using a table for the journal) and its schema.
  • option 2 requires DB connection credentials, network routing, security signoff, certificates, etc
  • option 1 means the microservice has the increased responsibility of publishing events
  • option 2 means there is another application to build, deploy, operate and maintain
  • both options will work

Which is (closer to) best practice?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.