Skip to content

Porting from gRPC

Use this guide to port a small gRPC service while preserving its application behavior. For example, a Greeter with one unary call and one server stream can move to peer-addressed RPC, but its client discovery, credentials, deployment, and failure tests also need migration.

Run the Python first service before adapting the fragments below. TypeScript needs its metadata build. These examples explain the translation; they are not a complete deployment or a wire-compatible adapter for existing gRPC clients.

gRPC Aster Notes
.proto file @service / @rpc decorated class Python inspects annotations; TypeScript generates metadata; JVM uses processors.
Protocol Buffers Fory (XLANG mode) Cross-language binary serialization with @wire_type tags.
protoc code generator Binding-specific tooling Code-first definitions still need the chosen binding’s build and codec setup.
gRPC channel Aster endpoint (NodeAddr) Identity-addressed, not hostname-addressed.
HTTP/2 transport QUIC transport Direct, hole-punched, or relayed paths depend on reachability.
Load balancer Application service selection An endpoint address identifies one peer; it does not choose among replicas.
TLS certificates Iroh endpoint identity Peer authentication uses Ed25519; HTTP listeners still need TLS configuration.
Service mesh sidecar Review each responsibility Configure admission, authorization, telemetry, routing, and operations for your deployment.

Step 1: Replace .proto definitions with decorated classes

Section titled “Step 1: Replace .proto definitions with decorated classes”

Before (gRPC):

greeter.proto
syntax = "proto3";
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
rpc StreamGreetings (HelloRequest) returns (stream HelloReply);
}
# Generated by protoc -- do not edit
from greeter_pb2 import HelloRequest, HelloReply
from greeter_pb2_grpc import GreeterServicer
class GreeterImpl(GreeterServicer):
def SayHello(self, request, context):
return HelloReply(message=f"Hello, {request.name}!")
def StreamGreetings(self, request, context):
for i in range(5):
yield HelloReply(message=f"Hello #{i}, {request.name}!")

After (Aster):

from dataclasses import dataclass
from typing import AsyncIterator
from aster import service, rpc, server_stream, wire_type
@wire_type("myapp/HelloRequest")
@dataclass
class HelloRequest:
name: str = ""
@wire_type("myapp/HelloReply")
@dataclass
class HelloReply:
message: str = ""
@service
class Greeter:
@rpc
async def say_hello(self, req: HelloRequest) -> HelloReply:
return HelloReply(message=f"Hello, {req.name}!")
@server_stream
async def stream_greetings(self, req: HelloRequest) -> AsyncIterator[HelloReply]:
for i in range(5):
yield HelloReply(message=f"Hello #{i}, {req.name}!")

The decorated class defines the contract. Python reads its annotations at runtime; TypeScript requires the aster-gen metadata build step.

Step 2: Replace generated stubs with AsterClient

Section titled “Step 2: Replace generated stubs with AsterClient”

Before (gRPC):

import grpc
from greeter_pb2 import HelloRequest
from greeter_pb2_grpc import GreeterStub
channel = grpc.insecure_channel("localhost:50051")
stub = GreeterStub(channel)
response = stub.SayHello(HelloRequest(name="World"))
print(response.message)

After (Aster):

from aster import AsterClient
async with AsterClient(address="aster1...") as client:
greeter = await client.client(Greeter)
resp = await greeter.say_hello(HelloRequest(name="World"))
print(resp.message)

Python constructs the client proxy at runtime from the decorated class. Distribute compatible service and payload definitions to typed callers; dynamic callers need the published manifest.

Step 3: Replace gRPC server with AsterServer

Section titled “Step 3: Replace gRPC server with AsterServer”

Before (gRPC):

import grpc
from concurrent import futures
from greeter_pb2_grpc import add_GreeterServicer_to_server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
add_GreeterServicer_to_server(GreeterImpl(), server)
server.add_insecure_port("[::]:50051")
server.start()
server.wait_for_termination()

After (Aster):

from aster import AsterServer
async with AsterServer(services=[Greeter()], allow_all_consumers=True) as srv:
print(f"Listening at: {srv.address}")
await srv.serve()

This server fragment explicitly permits unenrolled callers for development. Configure admission and method permissions before using real application data.

The Python @service class defines the contract. TypeScript uses aster-gen to preserve type metadata before compilation.

Aster runs over QUIC (RFC 9000) on UDP. Iroh can use direct paths, hole punching, and relays. Test reachability under the deployment’s firewall and NAT policy; a relay does not provide application replica selection.

Peers connect directly by identity. The endpoint_addr encodes the node’s public key and relay hints, not a hostname. Connections are authenticated at the transport layer by the node’s ed25519 identity key.

QUIC connections are encrypted by default. The node’s identity key provides mutual authentication. Persist and protect that identity key, and plan credential and key rotation. HTTP integrations have a separate certificate policy.

Aster supports the same four patterns as gRPC: unary, server streaming, client streaming, and bidirectional streaming. Each pattern has binding-specific cancellation, buffering, and error behavior; verify those details when porting.

Middleware availability and ordering differ by binding. Map each existing interceptor to an actual API in the chosen binding reference, including retries, deadlines, authentication, and telemetry. Do not infer equivalent behavior from matching names.

Port timeout behavior explicitly, including cancellation of handler work. Set a timeout on the method decorator or per-call. Use the binding’s method and per-call deadline settings; the shared Rust dispatcher enforces the resulting deadline. Python also exposes a DeadlineInterceptor, while the TypeScript preview does not.

Aster uses the same 17 status codes (0–16) as gRPC, with compatible semantics:

Code Name gRPC equivalent
0 OK OK
1 CANCELLED CANCELLED
3 INVALID_ARGUMENT INVALID_ARGUMENT
4 DEADLINE_EXCEEDED DEADLINE_EXCEEDED
5 NOT_FOUND NOT_FOUND
7 PERMISSION_DENIED PERMISSION_DENIED
13 INTERNAL INTERNAL
14 UNAVAILABLE UNAVAILABLE
16 UNAUTHENTICATED UNAUTHENTICATED

The full set includes all 17 codes (2, 6, 8, 9, 10, 11, 12, 15 are also supported).

gRPC streaming patterns map directly to Aster decorators:

gRPC pattern Aster decorator Python signature
rpc Method(Req) returns (Resp) @rpc async def method(self, req: Req) -> Resp
rpc Method(Req) returns (stream Resp) @server_stream async def method(self, req: Req) -> AsyncIterator[Resp]
rpc Method(stream Req) returns (Resp) @client_stream async def method(self, stream: AsyncIterator[Req]) -> Resp
rpc Method(stream Req) returns (stream Resp) @bidi_stream async def method(self, reqs: AsyncIterator[Req]) -> AsyncIterator[Resp]

The difference: gRPC uses generated iterator types; Aster uses standard AsyncIterator from Python’s typing module.

Map gRPC metadata, interceptors, and mTLS to Aster’s trust model in three separate steps:

  • Caller identity and credentials: choose a trusted signing root and enrollment credentials for your deployment. The Python high-level client presents credentials during consumer admission. Direct native RPC paths require their binding’s verification/admission integration. Application metadata and non-authentication interceptor behavior need separate migration decisions.
  • mTLS certificates become endpoint identity keys. Each node has an ed25519 keypair embedded in the QUIC transport. Keep HTTP listener certificates separate from Iroh peer authentication.
  • Authorization interceptors become capability requirements. Declare @service(requires=...) or @rpc(requires=...) and the framework enforces them at the method dispatch layer.
  • NAT traversal. Test direct paths, hole punching, and relay access under the deployment’s firewall policy. A reachable relay can carry traffic when a direct path is unavailable; network policy can still prevent connection.
  • Peer-to-peer. Once a direct path is established (via hole punching or local discovery), traffic flows directly between peers with no intermediary.
  • Content-addressed contracts. Each service version gets a deterministic contract_id (a hash of its interface). Compare the descriptor to check interface agreement, then execute representative payload and failure tests; a matching ID does not qualify codec behavior for every value.
  • Discovery. Python consumer admission returns service information. Replica selection, address distribution, and manifest availability remain deployment responsibilities.
  • Relay availability. Deployments still need a reachable network path and may depend on a public or self-hosted relay.

For this Greeter, a unary request for World should return Hello, World!; the stream should yield five greetings and end. Test an unknown method, a denied caller, a deadline during a stream, and a disconnected client. Confirm handlers release their resources on cancellation using the chosen binding’s lifecycle rules.

Keep the original gRPC endpoint available until callers have migrated. Aster Fory frames cannot be consumed by an unchanged gRPC client. Roll back application routing together with the matching client package and stored contract metadata.