Kiến thức chung · Advanced · Data plane có bound
Chọn message, File Lane hay Stream Lane
Message giữ command, event và metadata nhỏ. File Lane
chuyển một object bất biến có size và SHA-256. Stream Lane chuyển một
chuỗi frame đang được tạo dần. Cả hai lane giữ bulk bytes ngoài
Envelope.payload.
01 · Chọn theo dữ liệu
Kích thước lớn không tự biến dữ liệu thành stream
CoAkka Runtime message
Command, query, event, reference hoặc metadata nhỏ. Target, correlation và Deadletter giữ control flow.
File Lane
Object bất biến đã biết size cuối, cần SHA-256, staging bền, resume và atomic publication.
Stream Lane
Nguồn live hoặc sinh dần, có frame boundary, chưa biết size cuối và cần byte-credit backpressure.
- Video đã ghi hoặc model binary
- Dùng File Lane nếu receiver cần nguyên object, integrity và resume.
- Camera, microphone hoặc telemetry đang chạy
- Dùng Stream Lane khi consumer xử lý từng frame và dữ liệu mới quan trọng hơn replay toàn bộ.
- Durable replay hoặc nhiều subscriber
- Dùng object store, event/media system hoặc app-host fan-out ở phía trên. Stream Lane v1 là point-to-point, không phải broker hay player protocol.
control plane: authorize + exchange identity/grant
CoAkka Runtime message: command, event, metadata, result
File Lane: bounded point-to-point immutable bytes
Stream Lane: bounded ordered point-to-point frames
02 · File Lane
Receiver prepare trước; integrity quyết định completion
Ứng dụng authorize operation, tính exact size và SHA-256, rồi receiver prepare destination với transfer ID và transfer-scoped token. Sender chỉ submit sau khi có exact receiver endpoint. Receiver ghi staging file, publish durable checkpoint, verify toàn bộ digest rồi atomic replace destination.
Lane configuration
- Directions
- Bật sender, receiver hoặc cả hai. Chỉ mở direction process thực sự sở hữu.
- Bind host/port
- Listener của receiver; port 0 cho phép Core chọn port thực tế.
- Queue capacity
- Default 8, hard ceiling 64 cho queued work, prepared receives và retained records.
- Maximum file size
- Default 4 GiB. Vượt bound trả
SIZE_LIMIT, không âm thầm buffer. - I/O timeout
- Default 30 giây cho idle network/TLS operation.
- Checkpoint bytes
- Default 4 MiB.
committed_offsetlà receiver-durable resume truth. - Progress thresholds
- Default mỗi 1 MiB hoặc 250 ms, điều kiện nào tới trước; độc lập với checkpoint.
- Workers
- Default 1 sender và 1 receiver; tối đa 4 cho mỗi direction.
- Security
DIRECT,TLShoặcMUTUAL_TLS; cố định suốt lane lifetime.
Per-transfer fields
- Transfer ID
- Identity duy nhất của prepared transfer và retained record.
- Authorization token
- Bearer capability cho đúng transfer; không log hoặc dùng cho transfer khác.
- Destination path
- Receiver-owned path được authorize trước; remote peer không gửi filesystem path tùy ý.
- Source path
- Sender-owned immutable source. Open handle được giữ để path replacement không đổi identity.
- Expected size + SHA-256
- Hai phía phải khớp. Source change hoặc integrity mismatch là explicit terminal result.
- Remote endpoint
- Exact receiver owner host/port, không phải replica-load-balancing Service address.
Sender báo thành công chưa đủ để app sử dụng file. Receiver phải đạt
COMPLETED + OK; local 100% bytes cũng không thay thế
verified receiver completion.
03 · Stream Lane
Publisher chỉ tạo frame khi subscriber còn byte credit
Publisher prepare một session với source callback, session ID, token,
format_id và maximum frame size. Subscriber dùng cùng grant,
khai báo bounded receiver window và consumer callback. Frame giữ thứ
tự; credit chỉ trở lại sau khi consumer xử lý xong.
Lane configuration
- Directions
- Bật publisher, subscriber hoặc cả hai theo ownership của process.
- Bind host/port
- Listener của publisher; owner-aware grant trả direct advertised endpoint cùng actual port.
- Capacity
- Default 8, hard ceiling 64 cho prepared publishers, queued subscribers và retained records.
- Maximum frame
- Default 256 KiB, hard ceiling 4 MiB. Mỗi frame phải non-empty và nằm trong negotiated bound.
- Receiver window
- Default bốn maximum-sized frames, hard ceiling 16 MiB và phải giữ được ít nhất một max frame.
- I/O timeout
- Default 30 giây cho idle transport operation.
- Source retry
- Default 5 ms sau
WOULD_BLOCK; source callback không được block vô hạn. - Progress
- Default mỗi 30 frame hoặc 250 ms.
- Workers
- Default 1 publisher và 1 subscriber; tối đa 4 cho mỗi direction.
- Pressure timing
- Default pressured 100 ms, stalled 1000 ms, recovery 500 ms và observation 100 ms; mỗi interval tối đa 60 giây.
- Security
DIRECT,TLShoặcMUTUAL_TLS; token vẫn authorize session.
Session và frame fields
- Session ID
- Identity của prepared publisher/session record.
- Authorization token
- Single-admission capability; valid
OPENđầu tiên consume token. format_id- 64-bit app compatibility identifier. Core so sánh nhưng không parse codec/schema.
- Maximum frame bytes
- Hai phía negotiate cùng bound; không phải target bitrate hay codec setting.
- Initial window bytes
- Bound cho in-flight payload; publisher ngừng khi hết credit.
- Sequence
- Core gán từ 1 và tăng từng frame để consumer quan sát ordering.
- Capture timestamp
- Monotonic timestamp từ source hoặc monotonic time của CoAkka Runtime khi source để 0.
- Flags / dropped before
- Keyframe, discontinuity, segment boundary và số frame/sample source đã drop.
Consumer chỉ mượn frame bytes trong callback. Dữ liệu cần giữ phải được copy trước khi callback trả về. Source callback nhận writable buffer do CoAkka Runtime cấp cũng không được giữ pointer hoặc destroy lane bên trong callback.
04 · Replica ownership
Grant thuộc đúng process đã prepare state
Simple
Dùng khi một owner có endpoint ổn định hoặc application control state đã pin ID, token, metadata và endpoint vào cùng một record.
Owner-aware
Dùng khi prepare command có thể chọn một trong nhiều replica. Grant mang exact owner instance và direct endpoint; connector phải feature-detect capability.
- Message route có thể dùng Kubernetes ClusterIP Service; lane grant không được reconnect qua Service load balancer.
- Dùng StatefulSet/headless DNS, pod DNS hoặc Pod IP khi network và certificate policy cho phép.
- Bind và advertise tách biệt. Certificate SAN phải khớp direct host trong grant.
- File token còn hợp lệ cho bounded resume khi exact owner vẫn giữ transfer record.
- Stream token là single-admission; transport failure sau valid OPEN cần prepare và token mới.
- Pod/lane loss làm mọi grant của owner đó mất hiệu lực; CoAkka Runtime không migrate destination, callback, committed offset hay pressure state sang replica khác.
05 · Lifecycle và evidence
Mỗi phía có terminal record riêng
File transfer
PREPARED → QUEUED → CONNECTING → TRANSFERRING → VERIFYING → COMPLETED, hoặc PAUSED / REJECTED / FAILED / CANCELED. Receiver COMPLETED + OK là authority.
Stream session
PREPARED → QUEUED → CONNECTING → ACTIVE → ENDED, hoặc REJECTED / FAILED / CANCELED. ENDED + OK chỉ nghĩa source kết thúc bình thường, không hứa durability/replay.
- Đợi bằng last
update_sequence; không busy-poll. Intermediate update có thể coalesce, terminal state được giữ lại. - Ghi nhận local terminal outcome ở cả hai peer. Một phía thành công không suy ra phía kia đã publish/consume thành công.
cancellà cooperative. Work đã hoàn tất và publish có thể thắng một late cancel.- Chỉ
forgetsau khi app đã lưu outcome. Forget xóa retained record của CoAkka Runtime, không xóa application-owned file. - Đóng lane sau khi wait/callback/API call đang chạy đã trả về; close dừng, wake waiter và drain owner.
File Lane báo queue, size, timeout, source-change, integrity, storage,
network và certificate failures bằng stable result. Stream Lane báo
pressure state INACTIVE / FLOWING / PRESSURED / STALLED /
RECOVERING cùng reason bits cho credit, transport hoặc consumer.
Các signal này là transport observation; app quyết định bitrate,
capture mode, retry, sink hay user-facing outcome.
06 · Review trước khi tích hợp
Checklist theo boundary
Application/control plane
- Authorize trước khi prepare.
- Sinh ID/token mạnh và không log grant.
- Giữ business metadata ngoài bulk-byte lane.
- Chọn destination/source/sink và post-success action.
- Sở hữu retry, resume, fan-out và quality policy.
CoAkka Runtime/Core
- Bound admission, workers, buffers và retained state.
- Validate identity, token, size/format và endpoint.
- Giữ transfer/session lifecycle, progress, pressure và terminal result.
- Verify file integrity và atomic publication.
- Không hiểu business payload, codec hoặc user authorization.
Deployment/security
- Chọn exact owner address, không lane qua replica Service.
- NetworkPolicy cho phép direct connection.
- DIRECT chỉ trong protected boundary.
- TLS SAN khớp grant host; mTLS không thay app authorization.
- Rotate credential bằng replacement lane theo contract hiện tại.
Host integration
- Đưa blocking wait ra khỏi UI/event loop.
- Copy borrowed Stream bytes trước callback return.
- Bound source/device waits để stop/cancel quan sát được.
- Đợi cả hai phía terminal, record rồi forget.
- Không đưa path, token hay unrestricted lane API vào browser renderer.