Skip to main content

DLR Processor — Domain Model

Status: populated Owner: Platform Engineering Last updated: 2026-04-18 Companion: SERVICE_OVERVIEW · DATA_MODEL · EVENT_SCHEMAS

1. Core Aggregates

DeliveryReceipt (root)

Represents a single delivery receipt received from an operator, correlated to an outbound SMS.

FieldTypeNotes
receiptIdReceiptId (UUIDv4)Internal primary key; generated on first write
messageIdMessageId (UUIDv4)FK → orch.sms_messages; null until correlated
accountIdAccountId (UUIDv4)Resolved from message correlation
operatorMessageIdstringCarrier-assigned ID; dedup key
operatorIdOperatorIdSource operator
rawStatstringOriginal carrier stat or status string
dlrStatusDlrStatusCanonical normalised status
deliveredAtInstantTimestamp from carrier or receipt arrival
errorCodestring | nullCarrier error code when FAILED/UNDELIVERED
correlatedAtInstantWhen correlation succeeded
createdAtInstantInsert timestamp

OrphanedReceipt (root)

Holds DLRs that arrived with an operatorMessageId that cannot be correlated to any known sms_messages row.

FieldTypeNotes
orphanIdUUIDv4Primary key
operatorMessageIdstringOriginal carrier ID
operatorIdOperatorIdSource operator
rawStatstringOriginal carrier stat
rawPayloadJSONBFull inbound event payload
receivedAtInstantEvent arrival time
resolvedAtInstant | nullSet if later reconciled
resolvedReceiptIdReceiptId | nullSet when reconciled

2. Value Objects

VOInvariant
ReceiptIdUUIDv4 branded type
MessageIdUUIDv4 branded type; validated against regex
AccountIdUUIDv4 branded type
OperatorIdUUIDv4 branded type
DlrStatusEnum; see §3
OperatorMessageIdNon-empty string; max 64 chars

3. DlrStatus Canonical Enum

DlrStatusMeaningBillable
DELIVEREDHandset confirmed deliveryYes
FAILEDPermanent delivery failureYes
UNDELIVEREDCould not deliver; no retry possibleYes
EXPIREDMessage TTL elapsed before deliveryYes
REJECTEDOperator rejected before attemptYes
UNKNOWNStatus cannot be determinedNo

4. SMPP stat Normalisation Map

SMPP stat valueDlrStatus
DELIVRDDELIVERED
UNDELIVUNDELIVERED
EXPIREDEXPIRED
DELETEDFAILED
ACCEPTDUNKNOWN
REJECTDREJECTED
UNKNOWNUNKNOWN
FAILEDFAILED
(any other)UNKNOWN

5. Domain Events (internal)

EventTriggerKey Fields
DlrCorrelatedReceipt matched to messagemessageId, accountId, dlrStatus
DlrOrphanedNo match foundoperatorMessageId, operatorId, rawStat
DlrDuplicateoperatorMessageId already existsoperatorMessageId, existingReceiptId

6. Invariants

  1. operatorMessageId is globally unique within dlr.delivery_receipts (unique index enforces idempotency).
  2. Status transitions on orch.sms_messages only occur for terminal DlrStatus values (DELIVERED, FAILED, UNDELIVERED, EXPIRED, REJECTED).
  3. DlrStatus.UNKNOWN does not trigger billing events but does trigger webhook dispatch.
  4. An orphan record is written before any further processing; the NATS message is ACKed only after both DB writes succeed.