Contract identity
A service contract describes the calls a service accepts: its methods, request and response types, and contract settings. Aster derives a contract ID from that description so clients and providers can identify the interface they intend to use, even when they are written in different languages.
Suppose a Python client calls a Rust catalog service. Both need to agree on what a lookup request contains and what the response means on the wire. A service name alone cannot distinguish two versions with different response types. A contract ID gives each canonical interface its own identity.
When contract identity matters
Section titled “When contract identity matters”You encounter contract IDs when discovering a service, connecting implementations written in different languages, or rolling out an interface change. The ID identifies the interface; the endpoint identity identifies the peer hosting it. A peer can host several services.
For example, changing a catalog response type changes the contract ID. During a rollout, providers can continue advertising the old contract while clients move to the new one. An old client can look for its existing contract rather than assuming that every service named Catalog accepts the same calls.
Matching IDs establish agreement on the contract description. They do not establish that the caller is authorized, that implementations behave identically, or that every payload works across bindings. Apply the trust model and test the calls your application uses. Contract identity also does not automatically translate between versions.
You normally define a service using your language’s service APIs. The following sections explain how its identity is derived and what affects that identity; the service definition guide covers the application workflow.
Changes during a rollout
Section titled “Changes during a rollout”| Change | Contract consequence | Application action |
|---|---|---|
| Replace a handler implementation without changing its descriptor | ID stays the same | Test behavior and authorization independently |
| Change a request field’s wire type | Referencing contract gets a new ID | Keep compatible providers available while clients migrate |
| Change a method pattern or declared requirement | Descriptor and ID change | Compare generated contracts and retest callers |
A version or channel name helps people organize a rollout; it cannot make two different canonical interfaces interchangeable. See discovery for provider advertisements and channels.
Content-addressed identity
Section titled “Content-addressed identity”A contract_id is derived from the contract definition. Two implementations of the same service interface – whether written in Python, Java, Rust, or any other supported language – produce the same contract_id if they define the same methods, wire types, and contract settings.
The content determines the identity; a central registry does not assign contract IDs.
contract_id = blake3(canonical_xlang_bytes(ServiceContract))Canonical XLANG profile
Section titled “Canonical XLANG profile”For content addressing to work across languages, the serialized bytes must be identical regardless of which language produces them. Aster defines a constrained serialization profile called the canonical XLANG profile:
- Canonical field IDs. Canonicalization assigns 1-based IDs from NFC-normalized field-name ordering, independently of declaration order and caller-supplied IDs.
- Schema-consistent mode. No per-object type metadata in the payload. Types are known statically from the contract definition.
- No reference tracking. Recursive back edges use explicit named self-references, so object reference tracking is unnecessary.
- Standalone serialization. No session context, no shared caches, no state from prior objects. Each canonical byte sequence is self-contained.
- No compression. Canonical bytes are stored and hashed uncompressed.
- UTF-8 strings. All strings are encoded as UTF-8, even though Fory may normally choose LATIN1 or UTF-16 opportunistically.
- NFC-normalized identifiers. The profile requires Unicode NFC names. Low-level descriptor writers serialize the supplied names, so code constructing descriptors directly must supply normalized identifiers.
Aster uses a dedicated canonical encoder for contract identity. Use the SDK’s contract APIs to obtain these bytes; ordinary payload serialization with Fory is not a substitute for that encoder.
Type graph: a Merkle DAG
Section titled “Type graph: a Merkle DAG”Types reference each other by hash, forming a Merkle DAG (directed acyclic graph):
Each TypeDef is independently hashed. A MethodDef references its request and response types by hash. A ServiceContract references its methods. Changing any type in the graph changes its hash, which propagates upward through every contract that references it.
This gives you automatic change detection. If a type changes, every contract that uses it gets a new contract_id. Consumers looking up the old contract_id will find only providers that still advertise that contract.
Self-references and cycles
Section titled “Self-references and cycles”A type can refer back to itself, as a tree node does when it contains child
nodes. The canonical representation records a cycle back edge using a named
SelfRef rather than recursively embedding the referenced type. This lets
recursive definitions have a finite canonical representation.
ServiceContract
Section titled “ServiceContract”A ServiceContract is the top-level descriptor for a service:
| Field | Description |
|---|---|
name |
Service name (e.g., "TaskManager") |
version |
Integer version number |
methods |
List of MethodDef entries, sorted by name |
serialization_modes |
Supported serialization modes |
scoped |
Service scope: shared or session |
requires |
Optional service-level capability requirement |
producer_language |
Required for NATIVE mode; empty for interoperable modes |
The contract_id is the BLAKE3 hash of the canonical XLANG serialization of this structure.
MethodDef
Section titled “MethodDef”Each method in a service has a MethodDef:
| Field | Description |
|---|---|
name |
Method name (e.g., "assign_task") |
pattern |
RPC pattern: UNARY, SERVER_STREAM, CLIENT_STREAM, BIDI_STREAM |
request_type |
BLAKE3 hash of the request TypeDef |
response_type |
BLAKE3 hash of the response TypeDef |
idempotent |
Whether the method is safe to retry |
default_timeout |
Default timeout in seconds |
requires |
Optional CapabilityRequirement for authorization |
CapabilityRequirement
Section titled “CapabilityRequirement”Methods can declare authorization requirements that the trust model enforces:
| Kind | Meaning |
|---|---|
ROLE |
Caller must have a specific role attribute |
ANY_OF |
Caller must have at least one of the listed roles |
ALL_OF |
Caller must have all of the listed roles |
The shared Rust dispatcher checks declared requirements against the caller’s verified attributes before invoking network handlers. The admission or authentication policy supplies those attributes; they are not granted by the contract itself. See the trust model.
ContractManifest
Section titled “ContractManifest”Published contract collections contain the canonical contract bytes, canonical type bytes, and a JSON manifest:
| Member | Content |
|---|---|
contract.bin |
Canonical XLANG bytes of ServiceContract |
types/{hash}.bin |
Canonical XLANG bytes of each TypeDef |
manifest.json |
Contract ID, type hashes, methods, modes, and publication metadata |
The manifest can carry VCS provenance when supplied by the publisher. Consumers verify the canonical contract bytes against the advertised contract_id before using the bundle.
Continue with discovery or define a service.