Shared knowledge · Beginner → Advanced · Configure by intent
Envelope, Deadletter, OneWay and route selection
Business code calls a target. The Envelope describes the call, the route snapshot describes where that target can be handled, and a Deadletter records terminal delivery failure after CoAkka Runtime has admitted the message.
01 · Outcome boundary
Do not collapse three outcome layers into one error
- Before admission
- The host is not started or is closed, arguments cannot be copied, or the bounded ingress queue refuses work. The connector returns a synchronous failure; no Deadletter exists because Core did not admit the Envelope.
- After admission
- Routing, queue handoff, locality, remote transport or lifecycle prevents completion. CoAkka Runtime creates a Deadletter; an Ask normally matches it back to the pending caller.
- After business ownership
- The handler ran and returned a domain result or error. This is an
Envelope(kind=RESPONSE)with business status/error fields, not a Deadletter.
submit != OK → not admitted; handle the synchronous error
submit == OK → later delivery failure is a Deadletter
handler error → business RESPONSE, not a Deadletter
02 · Intent to message
Build from business intent, not from a list of 17 fields
- 1
Which capability?
Choose a stable target such as
billing.charge, then choose a reply-capableREQUEST, OneWay orEVENT. - 2
Which payload contract?
Set
message_type, schema version and format, then encode business data intopayload. - 3
Which submission identity?
Use a unique
message_id; an Ask also has correlation identity. The connector may generate those identities andreply_to. - 4
How long may it wait?
Set a finite
timeout_ms. This is the submission budget, not permission to retry the business effect. - 5
Which context must travel?
Add only small, bounded headers for trace, tenant, idempotency or a route key. Validate the combination before admission.
message_id: msg-01J...
correlation_id: ask-01J...
source: checkout-api
target: billing.charge
reply_to: checkout-api
kind: REQUEST
one_way: false
timeout_ms: 1500
message_type: billing.charge.v1
payload_schema_version: 1
payload_format: JSON
headers:
trace_id: trace-92f1
tenant_id: tenant-acme
idempotency_key: checkout-7842:charge
payload: '{"checkout_id":"7842","amount_minor":125000,"currency":"VND"}'
Headers should carry
Trace/request identity, app-authorized tenant context, a business idempotency key, one named affinity key and small operational tags.
Headers should not carry
Business fields that change command meaning, type/version/format with dedicated fields, large documents, binary data, login tokens, private keys or retry policy.
headers is context beside the payload, not a second payload
schema. Header names belong to the application contract.
route_key_hint only names the header a rendezvous route reads;
it does not make every header part of routing.
03 · Message contract
The Envelope has 17 fields with distinct responsibilities
A connector may generate or normalize some fields, but the wire contract means the same thing in every language.
message_id- Unique identity of this message instance, used for Deadletter matching and diagnosis.
correlation_id- Joins request and response; required for a
RESPONSEand a non-OneWayREQUEST. source- Logical sender/responder identity for diagnosis, not payload identity.
target- Stable capability address used to route request/event traffic, such as
orders.quote. reply_to- Reply-path hint only for reply-capable requests; forbidden on responses and OneWay requests.
kindREQUEST,RESPONSEorEVENT; neverUNSPECIFIED.one_way- The sender expects no business response; a response cannot be OneWay.
timeout_ms- Caller delivery/wait budget; not a business SLA or automatic retry policy.
payload- Opaque business bytes that Core transports without interpreting.
headers- Small trace, tenant, request or idempotency context. Do not make it a second payload schema or log secrets.
status- Business outcome on a response; never a runtime delivery failure category.
error_code- Stable business error code on an error response.
error_message- Human-readable business diagnostic text, not a transport category.
delivery_hint- Local/remote preference or requirement for requests/events; responses use router default.
message_type- Stable name of the business payload contract.
payload_schema_version- Business payload contract version; typed paths use a positive version.
payload_formatJSON,PROTOBUF,THRIFT,MSGPACK,PLAIN_TEXTorBINARY.
Easy-to-miss semantic checks
- A
RESPONSEneedscorrelation_id, cannot be OneWay, has noreply_toand cannot overridedelivery_hint. - A reply-capable
REQUESTneedscorrelation_id; a OneWay request cannot carryreply_to. - An invalid combination is rejected by the connector before submit or becomes
INVALID_ENVELOPEif an encoded envelope was admitted.
04 · Delivery expectation
OneWay means only “do not wait for a business response”
Ask / reply-capable command
REQUEST + one_way=false. The connector retains a pending Ask to match a response, Deadletter or caller timeout.
Fire-and-observe
REQUEST + one_way=true. No pending Ask or business response; admission errors remain synchronous and later failures remain observable.
Domain event
EVENT, normally OneWay. Use the deadletter surface, stats and monitor events when delivery evidence matters.
Business reply
RESPONSE + one_way=false. Matches through correlation ID and carries the business outcome.
OneWay is not a delivery hint, overload policy or guaranteed delivery.
A OneWay API does not allocate a pending Ask merely to look like
request/reply. Policy may shed admitted OneWay work as
ONE_WAY_DROPPED_BY_POLICY; the app observes its counter and
Deadletter surface when loss matters.
Delivery hint is a separate axis
ROUTER_DEFAULT- Use normal route policy.
PREFER_LOCAL- Prefer a local eligible endpoint but permit remote delivery.
REQUIRE_LOCAL- Fail with
LOCALITY_MISMATCHif current placement cannot deliver locally. REQUIRE_REMOTE- Fail with
LOCALITY_MISMATCHif current placement cannot deliver remotely.
05 · Terminal delivery evidence
A Deadletter records which message failed, why and in which topology
original_envelope- The submitted Envelope, including its
message_idand originalpayload. reason- Stable machine-readable runtime failure category.
detail- Human-readable diagnostic text; never parse it as an error category.
active_generation- Route/control generation active when the failure was produced.
resolved_host/port- The chosen destination when resolution had progressed that far.
endpoint_attempt_count- Core endpoint attempts consumed by this outcome, not application retries.
transport_failure_metadata- Optional bounded facts under schema
transport-failure/1.
A Deadletter may be produced by either runtime
Caller-side CoAkka Runtime
No snapshot, route miss, locality mismatch, budget expiry before delivery, connection/TLS failure or remote reply timeout. The sending runtime builds a Deadletter from the admitted Envelope.
Peer CoAkka Runtime
The request frame reached the peer, but its queue refused work, runtime is stopping, target/handler is absent or local handoff failed. The peer builds a Deadletter; caller runtime fails over when evidence permits, otherwise forwards it to the app host.
No Envelope yet
If inbound TLS handshake fails before a request frame is decoded, no original_envelope exists for a Deadletter. The peer records a typed ingress/transport event instead.
Business handler
The handler accepts or rejects business work with a RESPONSE. That is not a Deadletter; if its terminal result does not return in time, the caller sees timeout ambiguity.
The current schema has no producer_runtime_id. Do not infer
physical origin from reason alone. Retain the selected
endpoint and correlate active_generation, host/port,
transport metadata, forwarded-deadletter counters and monitor events.
“The caller has no route” and “the peer has no target” fail at
different boundaries.
06 · Failure-mode lookup
Each reason answers “which stage failed?”
The sending desk refused it
submit != OK: no admission means no Deadletter. The caller handles synchronous refusal.
Directory or post office
Snapshot, target, responsible host, locality or endpoint availability is wrong. Fix topology/configuration; submitting unchanged work only adds load.
Depot and delivery vehicle
Queue, local handoff, transport, lifecycle or security failed. Read structured evidence to learn whether Core can fail over safely or must end the attempt.
Delivered, receipt missing
REMOTE_REPLY_TIMEOUT: the peer may have received the request and the handler may have produced an effect. Reconcile before repeating the command.
Stable reasons and usual responses
0 UNSPECIFIED- Integration defect; retain the whole Deadletter for diagnosis.
1 NO_ACTIVE_SNAPSHOT- No route snapshot exists; apply startup/control configuration.
2 ROUTE_MISS- The target is absent; fix the target or route.
3 NO_RESPONSIBLE_HOST- The route has no responsible endpoint; repair the snapshot.
4 QUEUE_REJECTED- A bounded queue refused work; back off, shed load, then tune from evidence.
5 LOCAL_HANDOFF_FAILED- The local adapter refused handoff; inspect lifecycle and local pressure.
6 DELIVERY_FAILED- No narrower delivery/setup category applies; branch on reason and use detail only for diagnosis.
7 REMOTE_TRANSPORT_FAILED- Remote connection, exchange, protocol, pressure or resource failure; inspect structured transport facts.
8 RUNTIME_STOPPED- Runtime stopped before completion; fix drain/shutdown and retry only under app policy.
9 INVALID_ENVELOPE- Wire fields or their combination are invalid; fix the producer/connector.
10 ENDPOINT_UNAVAILABLE- Matching endpoints are draining or unavailable; await a route update or fail fast.
11 REMOTE_REPLY_TIMEOUT- The request crossed transport but no terminal result arrived in budget; delivery may be ambiguous, so reconcile before non-idempotent retry.
12 LOCALITY_MISMATCHREQUIRE_LOCAL/REMOTEcannot fit placement; fix the hint or route.13 EXPIRED_BEFORE_DELIVERY- The admitted Envelope exhausted its budget before onward delivery; reduce pressure or revise the budget.
14 ONE_WAY_DROPPED_BY_POLICY- Overload policy shed OneWay work to protect reply-capable work; verify that loss is acceptable.
15 REMOTE_TRANSPORT_SECURITY_FAILED- TLS/mTLS configuration or handshake failed; inspect the redacted security code.
07 · Failover, timeout and retry
Failover preserves the submission; user retry creates a new one
Think of an admitted Envelope as one registered parcel with one tracking number and one delivery deadline. If post office A is closed before accepting it, CoAkka Runtime may carry the same parcel to post office B while budget remains and safe evidence says A never accepted ownership.
- Core endpoint failover
- The same request lifecycle, Envelope identity and original deadline remain. Core tries another endpoint only with endpoint-scoped
NOT_DELIVERED, or when a peer returnsQUEUE_REJECTED,LOCAL_HANDOFF_FAILEDorRUNTIME_STOPPEDbefore handler ownership.endpoint_attempt_countcounts the post offices tried. - User/application retry
- The old submission has ended. The app creates a new Envelope, new
message_id, separate retry budget and preserves the business idempotency key when it is still the same logical operation. The app owns this decision, not Core. - No failover
- Once an endpoint may have accepted ownership, Core does not move the effect to another peer.
REMOTE_REPLY_TIMEOUTis terminal and ambiguous, not permission to try the next endpoint.
one admitted Envelope
endpoint A → NOT_DELIVERED, budget remains
endpoint B → RESPONSE
= one request, two endpoint attempts, no user retry
terminal Deadletter or timeout
app reconciles business identity
app may create a new Envelope + new message_id
= user retry, not endpoint failover
A timeout is like a meal pager that did not buzz
When the deadline passes without a buzz, the kitchen may not have accepted the ticket, may still be cooking, may have finished while the pager failed, or may have sent a late signal. Timeout proves only that the caller observed no terminal result within budget; it does not prove that the handler never ran.
Read/query
A short bounded user retry may be acceptable when another read creates no side effect and system pressure permits it.
Idempotent command
Retry with a new Envelope while preserving the business idempotency key; the handler returns the recorded outcome instead of applying the effect twice.
Non-idempotent command
For a charge, query/reconcile by business identity, await a late outcome when exposed, or enter compensation/manual review before submitting again.
- 1
Classify the outcome
Synchronous refusal, Deadletter, business response, caller timeout or
REMOTE_REPLY_TIMEOUT. - 2
Read the attempt chain
Retain message/correlation ID, target, generation, endpoint, attempt count and idempotency key. Endpoint attempts are not user retries.
- 3
Reconcile ambiguity
Verify the previous effect before a non-idempotent retry. Do not infer it from the absence of a reply.
- 4
Retry only when safe
Create a new
message_id, preserve business identity and consume a bounded application retry budget.
08 · Topology configuration
The route snapshot owns topology; the call site keeps only the target
In the public contract the strategy is named
WEIGHTED_ROUND_ROBIN; weight is a field on each
endpoint, not a separate strategy named WEIGHT. A newer
generation replaces the whole published topology; a stale or invalid
update does not change the active snapshot.
generation- Monotonic snapshot version; begin at 1 and never reuse an older generation for new topology.
target- Unique routing key in a snapshot; business code calls this name, not a replica.
strategy- Ownership/selection algorithm across eligible endpoints.
route_key_hint- Header name used by rendezvous hash; required for that strategy.
route flags- For example
PREFER_LOCALwhen local selection should win if strategy permits. endpoints[]- Places where the target can be handled.
host/port- Concrete advertised destination; a wildcard bind address is not a route identity.
weight- Relative input for weighted/rendezvous selection. Zero normalizes to 1; it is not a percentage, priority or concurrency limit.
LOCAL- The endpoint belongs to this process; the process must register the target handler.
NONE- Zero flag; in a caller snapshot, read it as an ordinary eligible peer.
UNAVAILABLE- Keeps an endpoint visible in the snapshot while excluding it from new request selection.
Single owner
Exactly one endpoint owns the target. Use it for owner-bound commands and the local baseline; fail closed instead of selecting arbitrarily.
Weighted round robin
Equivalent handlers share work. A larger weight receives a larger relative share of selections while the endpoint remains eligible.
Rendezvous hash
A stable key tends to stay on one endpoint. Use it for sharding, ownership or cache locality; endpoint-set changes can still remap some keys.
generation: 42
routes:
- target: orders.validate
strategy: WEIGHTED_ROUND_ROBIN
endpoints:
- host: orders-a.default.svc.cluster.local
port: 19301
weight: 2
flags: [NONE]
- host: orders-b.default.svc.cluster.local
port: 19301
weight: 1
flags: [NONE]
Read this as “A receives roughly two selection shares for every one share of B while both are eligible,” not “A has two connections” or “A has absolute priority.” Do not configure weighted round robin for one Kubernetes Service DNS endpoint: CoAkka Runtime cannot see the pod list to select among it; Kubernetes owns that distribution.
09 · Review before integration
Checklist by owner
Message contract
- Target is a stable capability, not a replica name.
- Payload has an explicit type, schema version and format.
- Business data stays in payload; headers hold small context and never logged secrets.
- Ask, OneWay or Event follows response expectation.
- Timeout is a wait budget, not retry permission.
Topology
- Begin with single owner or one Service DNS endpoint.
- Expand endpoints only when CoAkka Runtime really must select topology.
- Use weighted routing for equivalent handlers and rendezvous for stable-key ownership.
- Weights and flags match effective topology; generation changes only with the snapshot.
- App host/control plane publishes the snapshot; a business handler does not mutate routes.
Failure handling
- Separate pre-admission error, Deadletter, business response and caller timeout.
- Branch on stable reasons/metadata, never parse
detail. - OneWay still has deadletter/stats/monitor evidence.
- Separate Core failover inside one Envelope from user retry with a new Envelope.
- Do not blindly retry route miss, invalid envelope or a non-idempotent timeout.
- Retain target, generation, selected endpoint and attempt count in evidence.
Ownership
- Core owns validation, route selection, correlation, failover evidence and terminal delivery outcomes.
- The connector maps typed values and keeps lifetimes safe.
- Platform/app host owns discovery, snapshot source and rollout.
- The app owns payload meaning, authorization, idempotency, retry/fallback and business errors.