Product knowledge · Advanced · Live control

Đổi route đang chạy mà không tráo handler của request đã admit.

Prepare và validate candidate trước. CoAkka HTTP Runtime chỉ atomically publish khi Core-issued generation/revision vẫn khớp; request cũ giữ binding đã capture, request mới mới nhìn thấy cut.

01 · Choose the operation

“Live update” không phải một operation duy nhất

Cần đổiOperation đúngGiữ ổn định
Implementation của một routeHandler-only rebindRoute ID, method, path, body policy và structural generation.
Thêm/bỏ/đổi route hoặc API metadataComplete route publicationMột coherent snapshot được accept/refuse toàn khối trong reserved bounds.
Listener/protocol/I/O backend, static authority hoặc startup reservationReplacement service + traffic cutoverOld owner phục vụ/drain cho tới finite terminal lifecycle.

Không gọi mọi thứ là hot reload. CoAkka HTTP Runtime không watch source, compile code hoặc load module thay App Host.

02 · Ownership model

Core publish identity; App Host sở hữu code và lifetime

App Host / addon

Detect change, build/load candidate, validate dependency, authorize change, giữ bounded binding registry và rollback policy.

CoAkka HTTP Runtime

Capture binding khi admit request, compare generation/revision, atomically cut over, giữ exact activation receipt và trả effective state.

Connector

Chiếu typed request/outcome tự nhiên, giữ integer identity chính xác và bảo vệ callback/object lifetime qua host boundary.

Deployment

Thay service, chuyển ingress, giữ spare capacity và drain old instance khi live API không bao phủ thay đổi.

03 · Identity map

Mỗi số bảo vệ một domain khác nhau

Route structural generation
Version của complete accepted route table; không phải source-code version hoặc timestamp.
Metadata generation
Core-issued identity của coherent route/API metadata state; complete publication compare riêng với structural route generation.
Binding change sequence
Service-wide cut identity bảo vệ structural publisher khỏi ghi đè một handler rebind mới hơn.
Per-route binding revision
Revision của handler đang active cho đúng route; handler-only compare-and-apply dùng field này.
Handler binding ID
Application identity của handler đã prepare/register; request capture ID này khi admission.
Activation ID
Application-chosen idempotency identity của một control intent; exact replay lấy lại retained outcome, không apply lần hai.

Đọc snapshot từ Core. Không tự tăng generation/revision, reuse identity giữa service instances hoặc suy effective state từ local handler map.

04 · Handler-only flow

Prepare → validate → register → snapshot → activate → drain → retire

1

Prepare ngoài event loop

Build/load candidate và dependency; failure ở đây không chạm active route.

2

Validate + register

App Host kiểm contract/authorization rồi thêm binding vào registry hữu hạn.

3

Read Core snapshot

Lấy route generation, route ID, current binding ID/revision và binding-change sequence hiện hành.

4

Activate exact intent

Submit một activation ID với expected generation/revision và prepared binding ID.

5

Split admissions safely

Admission sau accepted cut capture binding mới; work đã capture binding cũ tiếp tục đúng handler cũ.

6

Observe retirement

Giữ old binding/code/state cho tới Core request proof và mọi application reference riêng đều hội tụ.

Advanced · Listener V1 · Node.js + Bun

Đổi handler mà vẫn giữ nguyên cổng HTTPS

Node.js và Bun 2.3.2 có swapHandler() cho Listener V1. Hàm thay callback của route đã tồn tại. Với listener đơn, dùng rebind có kiểm tra phiên bản. Ví dụ này giữ nguyên URL và listener.

Tạo chứng chỉ phát triển và cài gói npm 2.3.2 như ở bài 04. Lưu file bên dưới thành swap-handler.mjs. Chạy node swap-handler.mjs hoặc bun swap-handler.mjs trong thư mục đó.

swap-handler.mjs
import { resolve } from "node:path";
import { createInterface } from "node:readline/promises";

const connector = process.versions.bun
  ? "coakka-http-runtime-bun"
  : "coakka-http-runtime-node";
const { Builder, Response } = await import(connector);

let releaseOldRequest;
const oldRequestCanFinish = new Promise((resolve) => {
  releaseOldRequest = resolve;
});
let oldRequestEntered = false;

const service = new Builder()
  .multiProtocolListener({
    host: "127.0.0.1",
    port: 8443,
    credentialId: "portal-lab",
    credentialGeneration: 1n,
    certificateChainFile: resolve("certs/server-chain.pem"),
    privateKeyFile: resolve("certs/server-key.pem"),
  })
  .get("/hello/Ada", async () => {
    oldRequestEntered = true;
    console.log("Old handler entered; waiting for release.");
    await oldRequestCanFinish;
    return Response.text("before");
  })
  .start();

const terminal = createInterface({ input: process.stdin, output: process.stdout });
try {
  console.log(`https://127.0.0.1:${service.port}/hello/Ada`);
  await terminal.question("Start the first request; when it enters, press Enter to swap.\n");
  if (!oldRequestEntered) {
    throw new Error("Start the first curl request before swapping the handler.");
  }
  service.swapHandler("GET", "/hello/Ada", () => Response.text("after"));
  await terminal.question("Handler swapped. Check new requests, then press Enter to release the first.\n");
} finally {
  releaseOldRequest();
  terminal.close();
  await service.close();
}

Ở terminal thứ hai, gửi request đầu tiên chạy nền. Chờ terminal dịch vụ in Old handler entered, rồi nhấn Enter ở terminal dịch vụ để đổi handler.

curl · before
curl --noproxy '*' --cacert certs/server-chain.pem --http3-only --max-time 30 \
  --fail --silent --show-error --write-out '\n%{http_code} %{http_version}\n' \
  https://127.0.0.1:8443/hello/Ada &

Trước khi cho request đầu tiên chạy tiếp, gửi 3 request bên dưới. Cả 3 phải trả after, mã 200 và đúng phiên bản. Nhấn Enter lần nữa ở terminal dịch vụ. Request đầu tiên trả before cùng 200 3, rồi dịch vụ đóng.

curl · after
for protocol in --http1.1 --http2 --http3-only; do
  curl --noproxy '*' --cacert certs/server-chain.pem "$protocol" --max-time 8 \
    --fail --silent --show-error --write-out '\n%{http_code} %{http_version}\n' \
    https://127.0.0.1:8443/hello/Ada
done

05 · Yêu cầu đổi handler

5 thuộc tính tạo thành một yêu cầu so sánh rồi áp dụng

Thuộc tínhÝ nghĩa và cách dùng
activation_idĐịnh danh duy nhất trong phạm vi điều khiển của service; khi thử lại phải giữ cùng ID và nguyên yêu cầu.
expected_route_generationPhiên bản cấu trúc route vừa đọc từ Core; không khớp nghĩa là candidate được chuẩn bị cho một bảng route khác.
route_idRoute ổn định cần đổi handler; bước áp dụng không chọn route bằng method/path dạng text.
expected_binding_revisionRevision hiện tại vừa đọc; ngăn 2 nguồn điều khiển ghi đè thay đổi của nhau trên cùng route.
new_handler_binding_idID của handler đã được chuẩn bị, kiểm tra và đăng ký; bước áp dụng không biên dịch hoặc tải handler.

06 · Rebind outcome

Giữ effective facts, không chỉ giữ một boolean success

Code
Stable control result. Chỉ APPLIED xác nhận accepted/replayed effective outcome.
Activation ID + operation digest
Correlation/operator evidence. Digest không thay exact field/byte comparison và không phải idempotency identity.
Route generation + binding-change sequence
Core-issued effective cut identities sau operation.
Previous/effective binding + revision
Cho biết route chuyển từ đâu sang đâu hoặc state nào được giữ nguyên khi refusal/replay.
changed / replayed
Phân biệt first accepted cut với exact retained replay; cả hai vẫn phải giữ effective fields.
Request retirement
Proof domain riêng với publication; activation success không tự cho phép unload old code.

07 · Control vocabulary

Stale, unresolved và refused cần action khác nhau

Stable codeÝ nghĩa / next action
APPLIEDDùng returned effective state; kiểm changed/replayed, rồi tiếp tục retirement.
GENERATION_MISMATCH / REVISION_MISMATCHĐọc lại snapshot và reconsider intent; không blind-increment số.
ACTIVATION_CONFLICT / EXPIRED / OUT_OF_ORDER / SEQUENCE_EXHAUSTEDIdentity/history/order không hợp lệ; giữ current state và phục hồi control-plane state trước operation mới.
INVALID_ARGUMENT / ROUTE_NOT_FOUND / REJECTEDCandidate/contract không hợp lệ; sửa intent hoặc prepared registry, không đổi active state.
TIMEOUT / WAKEUP_FAILEDKhông chứng minh operation bị reject. Retry exact activation + exact intent để lấy proof; không submit ID mới.
BUSYMột activation khác còn unresolved; operation này chưa submit và không consume history. Recover operation trước.
CLOSED / OUT_OF_MEMORY / INTERNALFail closed, giữ owner/evidence và xử lý đúng lifecycle/capacity/service boundary.

08 · Complete route publication

Đổi structure bằng một snapshot hoàn chỉnh, không patch từng route

prepare every referenced handler binding
  → read Core route identity
  → build complete candidate route array
  → publish against expected route + metadata + binding-change identities
  → accepted: entire candidate becomes effective
  → refused/stale: entire previous snapshot remains effective

route omitted from an accepted candidate = route removed

Publication có thể thêm/bỏ/đổi route structure và API metadata trong capability cùng construction-time reservations đã accept. Handler-only rebind vẫn là đường nhỏ hơn khi method/path/body policy không đổi.

09 · Publication fields

Structural publisher phải bảo vệ cả route, metadata và binding cuts

Request fieldÝ nghĩa
activation_idExact publication identity dùng cho idempotent replay.
expected_route_generationNgăn publish trên structural snapshot đã đổi.
expected_metadata_generationNgăn ghi đè coherent API metadata state mới hơn.
expected_binding_change_sequenceNgăn complete snapshot làm mất một handler rebind đã xảy ra sau lần đọc.
route_count + routesToàn bộ candidate snapshot với route ID, binding ID, method, encoded pattern, body policy và optional metadata; caller storage chỉ cần sống trong synchronous call.

Outcome trả previous/effective route, metadata và binding-change identities; actual/limit, rejected_route_index, changed/replayed và request-retirement proof. Branch bằng typed fields, không parse diagnostic prose.

10 · Request retirement

QUIESCENT chỉ chứng minh Core request captures của cut đó

StateRetirement law
UNKNOWNKhông có complete proof; partial source count không cho release.
CAPTUREDCut đã capture participating request owners nhưng chưa quiescent; tiếp tục giữ old binding.
QUIESCENTMọi Core request source của publication đã acknowledge cut. Chỉ request captures được chứng minh; callback/session/app reference vẫn phải tự hội tụ.
STILL_ROUTABLEOld handler identity vẫn có thể được route tới; tuyệt đối chưa retire.
NOT_APPLICABLEOperation không tạo retirement target phù hợp; không biến thành general permission để free object.

Chỉ code OBSERVED đi cùng proof quan sát được. UNAVAILABLE, BUSY, CONFLICT, EXPIRED, TIMEOUT, WAKEUP_FAILED, publication/observation failure và các error code khác đều yêu cầu giữ owner. Exact cold replay có thể lấy Core proof mới mà không resubmit route intent.

11 · Rollback

Rollback là một accepted change mới, không quay ngược đồng hồ

1

Giữ candidate cũ nếu policy cần

Binding chỉ có thể rollback khi code/state vẫn loaded, valid và registry còn capacity.

2

Đọc current Core state

Không reuse expected generation/revision từ trước cut.

3

Submit activation mới

Dùng activation ID mới với current compare fields và old binding ID đã chuẩn bị.

4

Drain binding bị thay thế

Giữ cùng retirement law; rollback không cancel magic work đã admit.

Exact replay của activation cũ chỉ trả retained outcome cũ; nó không phải rollback.

12 · Replacement service

Construction-time boundary vẫn cần instance mới

ChangeSafe path
Listener address/port, HTTP protocol hoặc I/O backendCreate/start/handshake new service, chuyển ingress, rồi drain old service.
Static mounts, file authorities hoặc startup resource/thread/queue reservationsBuild new validated service; live control không nới immutable reservation.
Capability chưa reserve, ví dụ WebSocket khi startup không reserveReplacement service với feature/capability được validate trước readiness.
TLS/mTLS credential cùng live modeDùng TLS reload contract riêng nếu exact target hỗ trợ; không gắn vào route publication.
Security mode/protocol hoặc package không hỗ trợ reloadReplacement service + real handshake evidence trước traffic cutover.
Application binary/module không thể unload/load an toànProcess/service rollout; không ép handler primitive vượt loader lifetime law.

13 · Failure law

Refusal không partial-publish; uncertainty không cho đoán

Prepare/validate failure

Candidate chưa active; discard trong App Host và giữ current handler.

Stale/refused apply

Core giữ entire previous effective state; read returned/current snapshot rồi reconsider.

Observation uncertainty

Timeout/wakeup failure không biết apply result; exact retry cùng intent để recover proof.

Drain/retirement timeout

Giữ old code/state reachable; timeout không phải permission để unload hoặc free.

14 · Bounds and evidence

Prepared, active, draining và history đều hữu hạn

15 · Integration checklist

Trước khi chọn API ngôn ngữ