1

I have been reading a lot about microservices and have been trying to logically split my system design up accordingly.

For the most part, my system will have a central database whereby I will have some triggers on important entity tables that will create an audit of all changes to the data. This trigger will write a log to the same database but in some separate tables.

I think that this data should exist in a separate database in another microservice. Is my thinking here correct with keeping with microservices architecture? What is the best way to move this data to another microservice? A batch job that runs every x minutes that moves the records to the audit microservice? I would like this data to be shipped to the auditing microservice as quick as possible. Does Postgres have a built-in function for this?

  • I'm afraid of the question is too broad and, as usually happens in this job, there's not a single way to achieve the goals. A good answer to this question might take us to do a consultancy of the project, its needs, requirements and constraints. Anyways, If I had to answer I would say: none of the options exposed are promising. In MS architectures , ideally, servicies don't share data. Services do things an others react accordingly. How to do this is also a broad subject. I would suggest reading about: MS choreography. – Laiv Jul 4 '18 at 17:34
  • It is hard to think of a case where you'd want to move data that are already in one database to some other database via microservice. There are plenty of tools (e.g. SQL Server Integration Services) that work at the database level that are far more efficient and more easily applied to the problem domain. – John Wu Jul 5 '18 at 8:39
2

Triggers are not a great way to create an audit.

You are limited in the data you can see, a single logical operation can create multiple records and as you have found its tricky to put the audit record somewhere other than the database.

In a microservice world you would protect your database with an api. The api would then write audit records to a separate Audit microserivce with its own datastore.

This has the advantage of giving you more control over the audit record, more information to put in it and allows you to centralise the audit data from many sources in a single place.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.