AshBilling.Deduplication (ash_billing v0.1.1)

Copy Markdown View Source

Deduplication engine for billing webhook events.

Supports two strategies:

  • :memory (default) - High-performance in-memory ETS table with hourly TTL cleanup. Best for single-node deployments and local development.
  • :resource - Database-backed Ash resource deduplication with unique constraint enforcement. Guarantees cross-node deduplication across clustered environments (e.g. Fly.io, Kubernetes, ECS).

Configuration

Via application config:

config :ash_billing,
  deduplication_strategy: :resource,
  deduplication_resource: MyApp.Billing.WebhookEvent

Or per-Plug in Phoenix Router:

forward "/webhooks/stripe", AshBilling.Plug,
  deduplication_resource: MyApp.Billing.WebhookEvent,
  domain: MyApp.Billing

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears all tracked events in memory (useful in tests).

Marks an event ID as processed.

Checks if an event ID has already been processed.

Starts the deduplication server and initializes the ETS table for memory strategy.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Clears all tracked events in memory (useful in tests).

mark_processed(event_id, opts \\ [])

@spec mark_processed(String.t() | nil, keyword()) :: :ok

Marks an event ID as processed.

processed?(event_id, opts \\ [])

@spec processed?(String.t() | nil, keyword()) :: boolean()

Checks if an event ID has already been processed.

start_link(opts \\ [])

Starts the deduplication server and initializes the ETS table for memory strategy.