The first API boundary should establish the context every later record can carry.

01

What the public implementation shows

CorrelationIdMiddleware accepts X-Correlation-Id or generates one, echoes it on responses, and bill creation stores it on BillCreated events.

The context is established before endpoint execution and flows into both technical logging and business event evidence. This is the implementation fact behind the note; the architectural reading begins from that visible boundary rather than from an assumed production story.

Operating principleThe first API boundary should establish the context every later record can carry.
02

The decision behind the mechanism

One entry-point mechanism avoids each authority or module inventing a different trace convention.

If correlation begins after bill persistence, the authority log and gateway event can no longer be joined deterministically. The mechanism matters because it gives that failure a named boundary, durable evidence, and a controlled response instead of leaving the outcome to timing or operator guesswork.

  • Validate inbound correlation values before logging.
  • Generate one when the caller omits it.
  • Echo it on every response.
  • Persist it with key business events.
03

How the control should be operated

The identifier format, maximum size, trust treatment, propagation headers, and logging scope should be consistent across clients and callbacks.

A revenue authority can follow one request through response, event polling, and later notification. The reusable lesson is not to copy a class or endpoint in isolation, but to preserve the relationship between identity, state, authority, evidence, and operational ownership.

Field conclusion

Establish correlation at the earliest API boundary and carry it into durable business evidence, not only request logs.

Public evidence ledger

Inspect the basis for this note.

These links point to public implementation evidence or authoritative documentation used for the claims above. The interpretation is mine; institutional code and ownership remain with their respective owners.

  1. 01
    Correlation middleware

    The middleware creates, scopes, and returns request correlation context.

    Open source evidence
  2. 02
    Correlation tests

    Tests verify supplied and generated identifiers across responses and events.

    Open source evidence