Skip to content

[Feature]: Idempotency Pipeline Behavior #224

@eneshoxha

Description

@eneshoxha

Title: Add idempotency pipeline behavior for at-least-once command delivery

Labels: enhancement, mediator, new-package

Body:

Problem

In event-driven systems using Cortex.Streams with Kafka (at-least-once delivery), the same command may be dispatched multiple times. Without idempotency support, this causes duplicate side effects.

Proposed Solution

Create a Cortex.Mediator.Behaviors.Idempotency package:

  • IIdempotentCommand interface with IdempotencyKey property
  • IdempotencyCommandBehavior<TCommand, TResult> -- checks if a command with the same key was already processed, returns the cached result if so
  • IIdempotencyStore interface with in-memory and pluggable (e.g., database/Redis) implementations
  • Configurable TTL for idempotency records
public class ProcessPaymentCommand : ICommand<PaymentResult>, IIdempotentCommand
{
    public string IdempotencyKey => $"payment-{OrderId}-{Amount}";
    public Guid OrderId { get; set; }
    public decimal Amount { get; set; }
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfeatureThis label is in use for minor version increments

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions