Kafka DeadLetter/Retry Scenarios
Error Retry and Dead-letter Scenarios
This document outlines the error retry and dead-letter handling strategies for services in the platform. Each service section details its approach to Kafka message processing failures, including retry logic and dead-letter queue (DLQ) handling.
Tenant Service
The Tenant service is responsible for producing the ReportScheduled Kafka message. It does not directly implement retry or dead-letter handling for this message. Instead, these actions are performed by downstream services that consume the message (such as Report, QueryDispatch, etc.).
- Message Production: Tenant produces the
ReportScheduledevent for downstream processing. - Error Handling: Retry and dead-letter logic for this message is managed by the consumer services, not by Tenant itself.
- See Also: Refer to the relevant consumer service sections for details on how retry and dead-letter scenarios are handled for
ReportScheduledand other messages.
Census Service
The Census service interacts with several Kafka topics as both a producer and consumer. Below are the error retry and dead-letter handling strategies for each relevant topic.
PatientListsAcquired (Consumer)
- Consumption: Census consumes
PatientListsAcquiredevents to process patient lists for facilities. - Retry:
- If message processing fails with a transient error, the message is retried according to the configured retry policy (using the shared
TransientExceptionHandler). - Exceptions triggering retry: Any exception of type
TransientException(e.g., temporary network issues, database timeouts, or other recoverable errors) will trigger the retry workflow. - Retry topics follow the
{TopicName}-Retrynaming convention.
- If message processing fails with a transient error, the message is retried according to the configured retry policy (using the shared
- Dead-letter:
- If all retries fail or a non-retryable error occurs, the message is sent to the
PatientListsAcquired-Errordead-letter topic (using the sharedDeadLetterExceptionHandler). - Exceptions triggering dead-letter: Any exception of type
DeadLetterException(e.g., validation errors, unrecoverable business logic errors) or unhandled exceptions not marked as transient. - DLQ topics follow the
{TopicName}-Errornaming convention.
- If all retries fail or a non-retryable error occurs, the message is sent to the
PatientEvent (Producer)
- Production: Census produces
PatientEventmessages to signal patient-related events (admit, discharge, etc.). - Retry:
- If message production fails, the error is logged and will enter retry topic for production failures in Census itself.
- Dead-letter:
- If retry fails after 5 attempts, the message will be deadlettered.
PatientCensusScheduled (Producer)
- Production: Census produces
PatientCensusScheduledmessages to schedule census-related jobs. - Retry:
- Production errors are logged, but there is no built-in retry topic for production failures in Census.
- Dead-letter:
- There is no built-in DLQ for production failures in Census. Downstream consumers handle dead-letter scenarios.
Data Acquisition Service
The Data Acquisition service manages FHIR queries and utilizes a state-managed background worker for execution.
DataAcquisitionRequested (Consumer)
- Consumption: Consumes
DataAcquisitionRequestedevents to initiate data retrieval logs. - Dead-letter:
- Exceptions triggering dead-letter: Throws
ArgumentNullException(triggering theDeadLetterExceptionHandler) if the CorrelationId is missing from headers.
- Exceptions triggering dead-letter: Throws
PatientCensusScheduled (Consumer)
- Consumption: Consumes
PatientCensusScheduledevents to trigger patient list updates. - Dead-letter:
- Exceptions triggering dead-letter: Throws
DeadLetterExceptionif the FacilityId is missing from the message key or if an error occurs during log creation.
- Exceptions triggering dead-letter: Throws
ReadyToAcquire (Consumer - Worker Logic)
- Consumption: The Acquisition Worker consumes
ReadyToAcquiremessages to execute FHIR queries. - Retry Strategy (State-Based):
ProcessingDelayException: If the execution date is in the future, the log status remains Pending to be picked up later.ProduceException: Production failures forResourceAcquiredmessages trigger aTransientExceptionfor Kafka-level retry.
- Dead-letter:
- Kafka DLQ: Thrown if the LogId or FacilityId is null or empty in the message.
- Internal Failure: If a general exception occurs during acquisition, the worker updates the DataAcquisitionLog status to Failed and records the error notes before throwing a
DeadLetterException.
Producers
- ResourceAcquired (Producer): Produces results of successful FHIR queries.
- Error Handling: Failures update the DataAcquisitionLog status to Failed. Producer failures are primarily managed via the worker's internal state logic.
Normalization Service
The Normalization service processes FHIR resources acquired by the platform to ensure they meet standard evaluation requirements.
ResourceAcquired (Consumer)
- Consumption: Consumes
ResourceAcquiredmessages containing FHIR resources or acquisition completion signals. - Retry:
- If a transient error occurs during processing, the message is retried via the
TransientExceptionHandler. - Exceptions triggering retry: Any exception not explicitly caught as a dead-letter or transient exception type will default to the retry workflow.
- Retry topics follow the
ResourceAcquired-Retrynaming convention.
- If a transient error occurs during processing, the message is retried via the
- Dead-letter:
- Messages are moved to the DLQ if a non-retryable error occurs or if metadata extraction fails.
- Exceptions triggering dead-letter:
- Missing FacilityId (message key).
- Missing or empty CorrelationId in the message headers.
- Unsupported resource types during deserialization.
- Validation failures, such as a null message value or missing ReportableEvent.
- DLQ topics follow the
ResourceAcquired-Errornaming convention.
ResourceNormalized (Producer)
- Production: Produces
ResourceNormalizedmessages after successful transformation. - Error Handling: If production fails, the error is logged. There is no built-in Kafka-level retry for producer failures; errors are surfaced to the background service.
Report Service
The Report service consumes and produces several Kafka topics. Below are the error retry and dead-letter handling strategies for each relevant topic, based on the actual code implementation.
ReportScheduled (Consumer)
- Consumption: Report consumes
ReportScheduledevents to schedule reports for facilities. - Retry:
- If message processing fails with a transient error (e.g., temporary network issues, database timeouts), the message is retried using the shared
TransientExceptionHandler. - Exceptions triggering retry: Any exception of type
TransientExceptionor general exceptions not explicitly marked as dead-letter. - Retry topics follow the
ReportScheduled-Retrynaming convention.
- If message processing fails with a transient error (e.g., temporary network issues, database timeouts), the message is retried using the shared
- Dead-letter:
- If a non-retryable error occurs (e.g., validation errors, duplicate report IDs), the message is sent to the
ReportScheduled-Errordead-letter topic using the sharedDeadLetterExceptionHandler. - Exceptions triggering dead-letter: Any exception of type
DeadLetterExceptionor unhandled validation/business logic errors. - DLQ topics follow the
ReportScheduled-Errornaming convention.
- If a non-retryable error occurs (e.g., validation errors, duplicate report IDs), the message is sent to the
PatientListsAcquired (Consumer)
- Consumption: Report consumes
PatientListsAcquiredevents to update patient submission entries for scheduled reports. - Retry:
- Transient errors (e.g., missing scheduled reports, temporary DB issues) trigger the retry workflow via
TransientExceptionHandler. - Retry topics follow the
PatientListsAcquired-Retrynaming convention.
- Transient errors (e.g., missing scheduled reports, temporary DB issues) trigger the retry workflow via
- Dead-letter:
- Non-retryable errors (e.g., invalid patient list data) are sent to the
PatientListsAcquired-Errordead-letter topic viaDeadLetterExceptionHandler. - DLQ topics follow the
PatientListsAcquired-Errornaming convention.
- Non-retryable errors (e.g., invalid patient list data) are sent to the
GenerateReportRequested (Consumer)
- Consumption: Report consumes
GenerateReportRequestedevents to generate or regenerate reports. - Retry:
- Transient errors (e.g., missing report schedule, temporary failures) trigger the retry workflow via
TransientExceptionHandler. - Retry topics follow the
GenerateReportRequested-Retrynaming convention.
- Transient errors (e.g., missing report schedule, temporary failures) trigger the retry workflow via
- Dead-letter:
- Non-retryable errors (e.g., invalid facility ID, missing required fields) are sent to the
GenerateReportRequested-Errordead-letter topic viaDeadLetterExceptionHandler. - DLQ topics follow the
GenerateReportRequested-Errornaming convention.
- Non-retryable errors (e.g., invalid facility ID, missing required fields) are sent to the
PayloadSubmitted (Consumer)
- Consumption: Report consumes
PayloadSubmittedevents to update submission status for reports and patients. - Retry:
- Transient errors (e.g., DB update failures, timeouts) trigger the retry workflow via
TransientExceptionHandler. - Retry topics follow the
PayloadSubmitted-Retrynaming convention.
- Transient errors (e.g., DB update failures, timeouts) trigger the retry workflow via
- Dead-letter:
- Non-retryable errors (e.g., invalid payload data) are sent to the
PayloadSubmitted-Errordead-letter topic viaDeadLetterExceptionHandler. - DLQ topics follow the
PayloadSubmitted-Errornaming convention.
- Non-retryable errors (e.g., invalid payload data) are sent to the
ResourceEvaluated (Consumer)
- Consumption: Report consumes
ResourceEvaluatedevents to process evaluated resources and update submission entries. - Retry:
- Transient errors (e.g., missing report schedule, deserialization issues, timeouts) trigger the retry workflow via
TransientExceptionHandler. - Retry topics follow the
ResourceEvaluated-Retrynaming convention.
- Transient errors (e.g., missing report schedule, deserialization issues, timeouts) trigger the retry workflow via
- Dead-letter:
- Non-retryable errors (e.g., missing correlation ID, invalid resource data) are sent to the
ResourceEvaluated-Errordead-letter topic viaDeadLetterExceptionHandler. - DLQ topics follow the
ResourceEvaluated-Errornaming convention.
- Non-retryable errors (e.g., missing correlation ID, invalid resource data) are sent to the
Producers
The Report service produces several Kafka topics. Below are the error handling and dead-letter strategies for each relevant producer, based on the actual code implementation.
DataAcquisitionRequested (Producer):
- Produces
DataAcquisitionRequestedmessages for each patient to trigger data acquisition. - Error Handling:
- If message production fails (e.g., Kafka unavailable), an exception is thrown and logged. There is no built-in retry or DLQ for production failures; failures are surfaced to the caller and may be retried by the job or service logic.
- Produces
ReadyForValidation (Producer):
- Produces
ReadyForValidationmessages when patient data is ready for validation. - Error Handling:
- If message production fails, an exception is thrown and logged. There is no built-in retry or DLQ for production failures; failures are surfaced to the caller and may be retried by the job or service logic.
- Produces
SubmitPayload (Producer):
- Produces
SubmitPayloadmessages to signal that a report or patient payload is ready for submission. - Error Handling:
- If message production fails, an exception is thrown and logged. There is no built-in retry or DLQ for production failures; failures are surfaced to the caller and may be retried by the job or service logic.
- Produces
ReportManifest (Producer):
- Produces report manifest payloads and triggers
SubmitPayloadproduction. - Error Handling:
- If manifest upload to blob storage fails, an audit event is produced and the failure is logged. If producing the
SubmitPayloadmessage fails, the error is surfaced as above.
- If manifest upload to blob storage fails, an audit event is produced and the failure is logged. If producing the
- Produces report manifest payloads and triggers
AuditableEventOccurred (Producer):
- Produces audit event messages for operational and error tracking.
- Error Handling:
- If message production fails, the error is logged. There is no retry or DLQ for audit event production failures.
Note:
- The Report service does not implement Kafka-level retry or dead-letter topics for producer failures. All error handling for producers is at the application/service level, with errors logged and surfaced to the caller for possible retry by the job or workflow logic.
Relationships
flowchart LR nerror_retry_scenarios_75C80AB2["Design: Kafka DeadLetter/Retry Scenarios"]