Kiến thức chung · Beginner → Advanced

Một target, hai billing service, một contract ở call site

checkout gọi billing.charge. Hai app-host có thể kết nối trực tiếp qua CoAkka Runtime trên LAN, private network, VM, bare metal hoặc edge. CoAkka Runtime chọn billing-a hoặc billing-b mà business code không giữ host list. Kubernetes không bắt buộc; failover, retry và rollout nằm ở phần Advanced.

Beginner · 01 · Distributed shape

Checkout gọi capability, không gọi replica

Giả sử hai process billing-a và billing-b cùng đăng ký handler cho target billing.charge. Chúng là hai endpoint tương đương của cùng một capability, không phải hai lần charge. CoAkka Runtime chọn đúng một endpoint cho request.

Đường distributed trực tiếp. checkout chạy OUTBOUND_ONLY; hai billing process chạy NETWORK_NODE. Chúng nói chuyện trực tiếp bằng transport của CoAkka Runtime, không cần Kubernetes Service, sidecar hay service-mesh data plane.

  1. 01
    Checkout ask billing.chargePayload có order, amount và business idempotency key.
  2. 02
    CoAkka Runtime đọc route generation hiện hànhRoute có billing-a và billing-b đang eligible.
  3. 03
    Một billing handler nhận ownershipEndpoint được chọn validate và charge theo business contract.
  4. 04
    Checkout nhận một terminal outcomeBusiness reply hoặc Deadletter/timeout có correlation.
checkout
  ask target=billing.charge
      ↓
CoAkka Runtime route generation 7
  ├─ billing-a:19301  eligible
  └─ billing-b:19301  eligible
      ↓ choose one
business reply / Deadletter / timeout

Call site vẫn giữ cùng target khi chạy Embedded, tách billing sang peer hoặc thêm replica. Topology owner thay route snapshot; business handler và caller không tự quản socket hay danh sách host.

Beginner · 02 · Outcome

Failover không biến mọi lỗi thành success

Business reply
Một billing handler đã nhận ownership và trả domain result. Success hoặc business refusal đều là response, không phải Deadletter.
Deadletter
Delivery không thể hoàn tất. Đọc stable reason, generation, resolved endpoint và endpoint_attempt_count.
Caller timeout
Không có matched terminal trong wait budget. Nó không chứng minh billing handler chưa chạy.
Không có route
ROUTE_MISS hoặc NO_ACTIVE_SNAPSHOT là config defect; gửi lại không sửa được topology.

Giữ Beginner đơn giản

Bắt đầu một billing handler Embedded. Chỉ tách hai peer khi cần scale, isolation, availability hoặc ownership boundary có thể giải thích.

Khi cần Advanced

Mở phần dưới khi CoAkka Runtime thấy nhiều endpoint trực tiếp, app cần hiểu ambiguous outcome hoặc operator đang rollout topology.

Advanced · 03 · Direct peer và route snapshot

Cấu hình peer trực tiếp trước, rồi mới chọn platform

checkout
  mode       OUTBOUND_ONLY
  listener   không có

billing-a
  mode       NETWORK_NODE
  bind       0.0.0.0:19301
  advertise  billing-a.internal
  port       19301

billing-b
  mode       NETWORK_NODE
  bind       0.0.0.0:19301
  advertise  billing-b.internal
  port       19301

billing-a.internal và billing-b.internal có thể là private DNS hoặc được thay bằng IP private ổn định. OS, container hoặc device supervisor quản lý process. App-host lấy topology từ static config, file/env, private DNS, registry, control plane hoặc Kubernetes rồi tạo route snapshot cho CoAkka Runtime.

Route snapshot trực tiếp, không phụ thuộc Kubernetes
generation: 7
routes:
  - target: billing.charge
    strategy: WEIGHTED_ROUND_ROBIN
    endpoints:
      - host: billing-a.internal
        port: 19301
        weight: 1
        flags: [NONE]
      - host: billing-b.internal
        port: 19301
        weight: 1
        flags: [NONE]
generation
Monotonic version của toàn snapshot. Topology đổi hoặc rollback đều publish generation mới cao hơn.
target
Capability address mà checkout gọi; không chứa replica name.
WEIGHTED_ROUND_ROBIN
Chia selection giữa handler tương đương. Weight là tỷ lệ tương đối, không phải concurrency limit.
RENDEZVOUS_HASH
Dùng khi cùng customer/order key nên ổn định về một owner; endpoint-set change vẫn có thể remap một phần key.
NONE endpoint flag
Zero flag; ở caller snapshot nghĩa là peer eligible bình thường.
UNAVAILABLE
Giữ endpoint trong snapshot/evidence nhưng loại khỏi selection mới để drain.

Direct không có nghĩa là tự tổ chức. CoAkka Runtime không tự discovery, quản lý membership, bầu leader, chạy consensus hay sửa split brain. Topology owner vẫn phải cung cấp identity và một snapshot nhất quán; Core sở hữu listener, transport, endpoint selection, bounded failover, correlation và outcome sau khi chấp nhận snapshot.

Kubernetes chỉ là một nguồn topology và lifecycle tùy chọn. Nếu route chứa một Kubernetes Service DNS, CoAkka Runtime thấy một endpoint và Kubernetes chọn pod. Nếu route chứa từng pod endpoint, CoAkka Runtime mới sở hữu selection, affinity, drain và failover evidence.

Tính weight từ tải đo được.

Advanced · 04 · CoAkka Runtime failover

Failover chỉ an toàn trước business ownership

Endpoint failover là một request lifecycle duy nhất: cùng business intent, correlation, active generation và monotonic deadline. Core loại endpoint đã thử rồi chọn endpoint eligible tiếp theo bằng route strategy; nó không reset timeout.

Core có thể fail over

  • Endpoint unavailable hoặc drained trước selection.
  • Connect/send thất bại trước accepted handoff.
  • Remote CoAkka Runtime từ chối admission trước handler ownership.
  • Forwarded Deadletter chứng minh pre-handler refusal như queue rejected, local handoff failed hoặc RUNTIME_STOPPED.

Core phải dừng attempt chain

  • Endpoint có thể đã nhận Envelope.
  • Handler có thể đã bắt đầu.
  • Remote reply timeout hoặc delivery certainty ambiguous.
  • Business handler đã trả response.
  • Invalid Envelope, route/handler mismatch hoặc terminal CoAkka Runtime outcome.

Luật transport chính xác. Chỉ failure có certainty=NOT_DELIVERED và scope=ENDPOINT mới cho phép automatic endpoint failover. Local profile, connection-scoped hoặc ambiguous failure không được sửa bằng cách âm thầm thử billing khác.

request #1 → billing-a
  connect failed before handoff (NOT_DELIVERED / ENDPOINT)
  remaining deadline → billing-b
  billing-b replies OK

application sees: one successful request
CoAkka Runtime evidence: endpoint_attempt_count=2

Advanced · 05 · Application retry

Retry là business attempt mới

Sau terminal outcome, application mới quyết định có submit lại hay không. Attempt mới dùng message_id mới, giữ business idempotency context, trừ vào retry budget và áp dụng backoff phù hợp. Core không thể đoán một lệnh charge có replay-safe hay không.

CoAkka Runtime failover đã success
Không retry ở app. Caller đã nhận reply cho request hiện tại.
REMOTE_REPLY_TIMEOUT
Outcome có thể ambiguous. Tra idempotency record hoặc reconcile với billing trước khi retry charge.
ROUTE_MISS / INVALID_ENVELOPE
Sửa topology hoặc producer; retry không thay đổi nguyên nhân và chỉ tăng load.
QUEUE_REJECTED / pressure
Back off, shed load hoặc chờ capacity. Chỉ tăng queue khi evidence cho thấy bounded burst phù hợp.
Business error response
Áp dụng domain policy. Declined card, duplicate charge và temporary provider failure không có cùng retry law.

Billing idempotency checklist

Advanced · 06 · Generation và rollout

Generation làm skew nhìn thấy được, không tạo global atomicity

  1. Một topology publisher/single-writer tạo snapshot kế tiếp; Core reject stale hoặc invalid update và giữ active snapshot.
  2. In-flight request giữ generation đã dùng khi route. Request mới dùng active local generation hiện tại.
  3. Hai process có thể tạm thời thấy generation khác nhau. Outcome phải ghi generation và endpoint thay vì che skew.
  4. Drain billing-a bằng snapshot mới có flag UNAVAILABLE, đợi work cũ, rồi remove ở generation sau.
  5. Rollback là một snapshot hợp lệ có generation cao hơn, không quay số generation về trước.
  6. Nếu cần atomic cutover toàn deployment, platform/control plane phải cung cấp protocol đó; CoAkka Runtime không tự trở thành consensus system.

Advanced · 07 · Operator evidence

Đếm endpoint attempt, không gọi nó là user retry

remote_failover_attempt_count
Số lần Core chọn replacement endpoint trong cùng request lifecycle.
remote_failover_success_count
Request đã dùng failover rồi hoàn tất bằng response.
remote_failover_exhausted_count
Có failover evidence nhưng hết endpoint eligible, matching generation hoặc deadline.
endpoint_attempt_count
Số endpoint attempt gắn vào terminal Deadletter của một request.
Recent event log
Bounded diagnostic context cho attempt/success/exhausted; có thể bị evict và không phải durable audit.
Business retry count
Application-owned metric riêng, gắn với idempotency key và user/business attempt.