top of page
Search

Transactional Outbox Design

  • Writer: varun sudan
    varun sudan
  • Mar 31, 2024
  • 2 min read

The Transaction Outbox design pattern is particularly useful in scenarios where you need to ensure reliable and consistent communication between different components or services, especially in distributed microservices systems. Here's a hypothetical use case to illustrate its utility:


Use Case: Ingestion Pipeline in Content Management System(CMS)

Consider a generic CMS. It's web based application that allows for fast search/retrieval of documents. Tech Stack could typically use Elastic Search for search capabilities, any modern day UI framework i.e React for rendering, Service layer to expose REST API endpoints.


Components Involved:

  1. Ingestion Service (IS): Responsible for ingesting new documents to make them searchable via API or UI.

  2. Client Service (CS): Client System responsible for calling Ingestion Service (IS) for uploading the document.

  3. ES Service (ISS): REST endpoints to store documents in Elastic Search Cluster.

  4. MetaData Storage Service (MSS): Service that is responsible for storing document metadata.

Scenario:

  1. Client Service: A client calls the ingestion service to upload documents.

  2. Ingestion service: Ingestion Service ingest the uploaded document by calling Storage Service as well as ES Service.

  3. Storage Service: Called by Ingestion service to store the metadata for the documents.

  4. Elastic Search Service: Called by Ingestion Service to store documents in a given index in Elastic Search.


Challenges:

  • Atomicity: Ensuring that either all steps (Storage service, ES processing) succeed or none of them do.

  • Consistency: Guaranteeing that the system remains in a consistent state even if there are failures during processing.

  • Reliability: Handling failures gracefully and ensuring that no steps are missed or duplicated during processing.


How Transaction Outbox Helps:


Implementing the Transaction Outbox pattern can address these challenges:

  1. Ingestion Processing Flow:

  • When the Ingestion Service receives a request to upload a document, it first saves the details in its database.

  • It then adds an entry to the Transaction Outbox, containing information about the document and the steps needed for processing the document.

  • The Ingestion Service acknowledges the request placement to the client, even before the processing is complete.

  1. Transaction Outbox Handling:

  • A separate component, say the Outbox Processor, periodically polls the Transaction Outbox for new entries.

  • It retrieves pending requests from the outbox and processes them one by one, ensuring that each step is executed reliably.

  • If any step fails during processing the transaction can be retried based on configurable retry policies.

  1. Idempotency and Reliability:

  • Each transaction step should be idempotent, meaning it can be safely retried without causing unintended side effects.

  • Idempotency ensures that even if a step is retried due to failures, the system remains in a consistent state, without processing the same step multiple times.

  1. Failure Handling:

  • If the Outbox Processor fails during processing, it can resume from the last successfully processed transaction, ensuring that no steps are missed or duplicated.

  • Failed transactions can be logged or moved to a separate dead-letter queue for manual inspection and resolution.

Conclusion:

In this use case, the Transaction Outbox pattern helps in orchestrating complex workflows involving multiple distributed services, ensuring reliability, consistency, and fault tolerance in the processing.

 
 
 

Comments


bottom of page