LinuxForHealth / FHIR

The LinuxForHealth FHIR® Server and related projects
https://linuxforhealth.github.io/FHIR
Apache License 2.0
333 stars 156 forks source link

Write audit records asynchronously #1746

Open punktilious opened 4 years ago

punktilious commented 4 years ago

Is your feature request related to a problem? Please describe. If writing an audit record fails, the request should fail (and the transaction rolled back). However, for best performance, writing audit records to streams like Kafka should be asynchronous (so you don't have to wait each time for ACKs from each required replica.

Describe the solution you'd like Use the async API to write the audit record, but capture a Future and add it to the TransactionData implementation class. The Futures can be resolved in the TransactionData#persist() method. If any of the writes failed, the transaction can be marked for rollback.

Describe alternatives you've considered Use synchronous API and accept the performance impact.

Acceptance Criteria At least one acceptance criteria is included.

  1. GIVEN a bundle write request WHEN the audit writes are successful THEN the request is success

  2. GIVEN a bundle write request WHEN an audit write fails THEN the request fails and the database is not changed

Additional context See com.ibm.fhir.persistence.jdbc.impl.ParameterTransactionDataImpl. The name of this class could probably be changed to something more general if it is going to support more than just parameter data.

lmsurpre commented 3 years ago

Kafka has APIs to support this already.