Skip to content

Rebuild as a Python-native framework for Apache Dubbo - #53

Draft
cnzakii wants to merge 1 commit into
apache:mainfrom
cnzakii:python-native-rebuild
Draft

cnzakii wants to merge 1 commit into
apache:mainfrom
cnzakii:python-native-rebuild

Conversation

@cnzakii

@cnzakii cnzakii commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Fixes apache/dubbo#16595

Summary

This PR replaces the previous implementation with a new Python-native framework for Apache Dubbo. It runs on asyncio, with AnyIO for structured concurrency and uvloop as an option, and supports Python 3.11 to 3.14 on Linux, macOS and Windows.

It talks to Dubbo Java and Dubbo Go over both the Triple and Dubbo protocols, serves the same methods to plain HTTP clients, finds and registers services through ZooKeeper and Nacos as they do, and brings the governance of the other Dubbo languages to Python.

Highlights

  • Works with Dubbo Java and Go. Triple with Protobuf and Dubbo with Hessian 2, ZooKeeper and Nacos registries, and both application-level and interface-level service discovery. Wire formats and registry entries follow Dubbo Java and Dubbo Go.
  • Compatible with gRPC. Triple runs over HTTP/2, so gRPC clients and servers, grpcurl, health checks and reflection work with it. It also runs over HTTP/3 once a provider announces it.
  • Plain HTTP too. One port serves HTTP/1.1, HTTP/2 and HTTP/3, and every method also answers plain HTTP calls with JSON, so curl, browsers and web frontends call services without a stub.
  • Pythonic. A service is a typing.Protocol with type hints, calls are async, and an application runs inside async with, in any asyncio program. Each method of a reference has the name, signature, type annotations and docstring of its contract, so that tools that read them, such as AI agent frameworks, can take it as a function.
  • Governance built in. Load balancing, cluster fault tolerance, routing rules and dynamic configuration, as in the other Dubbo languages.
  • Extensible. Every protocol, registry, load balancer, router and filter is a plugin that a package can add through an entry point.
  • Measured. Benchmarks against Dubbo Java, Dubbo Go and the gRPC libraries of Python, and several rounds of tests at scale with fault injection, below.

Features

  • Protocols
    • Triple over HTTP/2, interoperable with gRPC: unary, server-streaming, client-streaming and bidirectional calls; deadlines, rich error details, and gzip, deflate and bzip2 compression; the gRPC health and reflection services; the wrapped mode for Java interfaces.
    • Triple over HTTP/3, with the http3 extra: a consumer moves a provider's calls to HTTP/3 once the provider announces it with Alt-Svc and a QUIC handshake succeeds, and falls back to HTTP/2 when it fails. HTTP/3 always runs over TLS.
    • One port for HTTP/1.1 and HTTP/2 over TCP, told apart by ALPN or by the connection preface, and HTTP/3 over UDP at the same number.
    • The Dubbo protocol with Hessian 2.
    • TLS and mutual TLS on both protocols.
  • Plain HTTP
    • Every method answers at /{interface}/{method}, with GET and POST; dubbo.get, dubbo.post and the other verbs declare routes with path templates, and dubbo.Path, Query, Header, Body and Form say where each parameter comes from.
    • Protobuf methods follow the google.api.http options of their .proto files, which protoc-gen-python-dubbo reads.
    • JSON is a serialization: protobuf messages as the proto3 JSON mapping, other types through pydantic with the json extra.
    • Errors as HTTP statuses with a JSON detail; CORS, and an OpenAPI 3.1 document with Swagger UI and ReDoc, when the settings enable them.
  • Services and calls
    • Contracts as typing.Protocol, or generated from .proto files by protoc-gen-python-dubbo.
    • A mapping of Java types, and generic calls without the contract.
    • Attachments and a call context that propagate along a chain of calls.
  • Service discovery
    • Application-level and interface-level registration on ZooKeeper and Nacos.
    • MetadataService 1.0.0 and V2, local and remote metadata, and metadata reports.
    • Configuration centers on ZooKeeper and Nacos.
  • Traffic management
    • Clusters: failover, failfast, failsafe, failback, forking, broadcast, available and zone-aware.
    • Load balancers: random, round-robin, least-active and consistent-hash.
    • Condition and tag routers, and dynamic configurators.
    • Filters for access logs, active-call and concurrency limits, TPS limits, tokens and deprecated methods.
  • Application
    • Configuration from code, from JSON, YAML and properties files, and from environment variables, in layers.
    • Lifetimes that open and close as a whole, and graceful shutdown within a time budget.
  • Packaging
    • The default installation serves and calls over both protocols. Extras add zookeeper, nacos, yaml, properties, uvloop, protoc, json and http3.

Samples

samples/ holds 22 samples, each with a README. The tests run them as their READMEs say. CI skips the logging, extensions, TLS, FastAPI and Pydantic AI samples, whose packages it does not install.

  • Basics: 17 samples, from a first call through registries, configuration, streaming, errors and timeouts, routing, filters, extensions, TLS and generic calls.
  • Interoperability: Python and Dubbo Java calling each other through Nacos over Triple and over Dubbo; Python and Dubbo Go over Triple; gRPC clients and servers.
  • Integrations:
    • A small shop behind a FastAPI gateway, with a trace id along the chain of services.
    • An AI agent built with Pydantic AI, which plans restocking with Dubbo services as its tools, with any model served through the Chat Completions API of OpenAI.

Performance

benchmark/ measures each server with the same echo service, Protobuf over Triple on HTTP/2 and Hessian 2 over Dubbo, under the same load: on Linux with a 32-core Xeon, the server pinned to its cores with taskset and the load on the others, the median of three rounds. None of the 81 million calls failed.

Calls per second, with 128-byte / 16 KiB payloads:

Server 1 core, Triple 1 core, Dubbo 8 cores, Triple 8 cores, Dubbo
Dubbo Python 13.5k / 10.8k 22.2k / 17.4k 13.7k / 10.7k 21.4k / 17.0k
Dubbo Java 5.1k / 3.1k 35.0k / 6.4k 85.6k / 50.4k 309k / 61.3k
Dubbo Go 6.8k / 2.5k 21.4k / 6.4k 45.0k / 17.9k 104k / 18.8k
grpcio 3.5k / 3.1k
grpclib 4.1k / 3.0k
  • On one core, Dubbo Python serves the most Triple calls of the servers measured, and over Dubbo about as many as Dubbo Go.
  • A Python process serves on one core, while Java and Go use every core they are given, so on hosts with several cores they serve more per process.

Tests at scale

Besides CI, the framework went through several rounds of tests at scale on Linux hosts, with providers and consumers in containers beside Dubbo Java, Dubbo Go, ZooKeeper and Nacos:

  • providers killed while they are called;
  • 50 providers with 50 consumers, and 100 services over 300 instances;
  • rolling releases and registry outages;
  • weights changed while calls run;
  • long runs;
  • the benchmarks above.

Compatibility

  • Public API: the API is new, so code written for earlier releases needs to be ported.
  • Wire formats and interoperability: wire formats and registry entries follow Dubbo Java and Dubbo Go, with golden files captured from them in the tests. The samples call Dubbo Java 3.3 over both protocols and Dubbo Go over Triple, through Nacos, and gRPC clients and servers.
  • HTTP/3: the tests call Triple over HTTP/3 between Dubbo Python peers, and the HTTP/3 server has served an aioquic client. Calls over HTTP/3 to and from Dubbo Java and Dubbo Go are not tested yet.

Testing

  • Tests: 2,070 unit and integration tests, with 94% line and branch coverage, without the generated code. The ZooKeeper and Nacos tests run against servers in Docker.
  • CI:
    • Ruff, ty and the license header check.
    • Tests on Linux, macOS and Windows with Python 3.11 to 3.14, with every extra installed, HTTP/3 included.
    • Fresh installs of the default installation.
    • Integration tests and the samples against ZooKeeper 3.8 and 3.9 and Nacos 2.4 and 2.5.
    • A package build check.
  • Time: the asynchronous tests run on a virtual clock that jumps to the next timer while every task waits. Deadlines, timeouts and grace periods are asserted exactly, whatever the speed of the host.

@cnzakii
cnzakii force-pushed the python-native-rebuild branch 9 times, most recently from a20307e to 1121c12 Compare November 16, 2026 12:37
@cnzakii
cnzakii requested a review from AlbumenJ November 17, 2026 03:16
@cnzakii
cnzakii force-pushed the python-native-rebuild branch 12 times, most recently from 60b148b to 6510188 Compare November 20, 2026 11:53
@cnzakii
cnzakii marked this pull request as ready for review November 20, 2026 12:12
@cnzakii
cnzakii removed the request for review from AlbumenJ November 20, 2026 13:26
@cnzakii
cnzakii marked this pull request as draft November 22, 2026 15:19
@RainYuY
RainYuY requested a review from AlbumenJ November 23, 2026 03:38
@cnzakii
cnzakii force-pushed the python-native-rebuild branch 2 times, most recently from 65efdcd to a504612 Compare November 23, 2026 07:36

@EarthChen EarthChen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the substantial work. I reviewed and ran this locally before commenting.

Verified green: uv sync --locked --all-extras; pytest tests/unit (1404 passed), pytest tests/integration -m "not zookeeper and not nacos and not samples" (552 passed); ruff check/format/ty check; the 01_hello_world sample end-to-end; 2070 tests confirmed via --collect-only; CI matrix green including the ZooKeeper/Nacos integration jobs. The Triple gRPC wire implementation (5-byte framing, grpc-timeout units, trailer-only responses, grpc-status-details-bin, compression negotiation) matches the gRPC HTTP/2 spec, and the Dubbo protocol header/body layout matches Dubbo Java's documented structure.

Requesting changes on four points:

  1. Dependency governance. The entire wire stack hard-depends on ngh2 (HTTP/2), h11r (HTTP/1.1) and hessian2 (serialization), plus ngquic for the http3 extra — all published under the PR author's account, created between July and November 2026 (ngquic two days before this PR), each with a single maintainer and no third-party adoption record. Established alternatives exist (h2, h11, aioquic); if the choice is a deliberate performance/design bet on Sans-I/O + native cores, please document it (ADR) with the benchmark evidence, and get explicit PMC sign-off on the dependency set. Additionally, NOTICE carries no third-party attribution while the wheels bundle libnghttp2, ngtcp2, nghttp3 and aws-lc — the release manager will likely require a DEPENDENCIES/NOTICE update before any release.
  2. Default security posture. By default a provider exposes every exported method over plain HTTP JSON (triple.rest.enabled defaults to true) and to $invoke generic calls over gRPC and Dubbo, with no built-in authentication (TokenFilter only activates when a token URL parameter is present) and TLS off. That is fine for samples but dangerous as a default. Please either invert the defaults (REST off by default, generic invoke gated) or add a prominent security note to the README/Configuration docs stating the exact unauthenticated surface a default deployment exposes.
  3. Claims I could not reproduce from the repo. (a) "94% line and branch coverage" — the new pyproject.toml has no coverage configuration and CI does not run coverage, so the number is unverifiable; please add a coverage job or drop the figure. (b) The "tests at scale" bullet (providers killed mid-call, rolling releases, registry outages) has no corresponding tests in the repository — the in-tree failure tests exercise graceful aclose() only. Either commit the harness or scope the claim.
  4. Migration. The public API is fully replaced (Client/Server are gone, Python ≥3.11, sync→async), which the PR acknowledges, but there is no migration guide; users of the previous release have only the new quick start and samples to reverse-engineer from. A MIGRATION.md mapping old → new would substantially reduce the break's cost.

Minor: SERIALIZATION_IDS advertises fastjson2 (id 23) but no fastjson2 serialization is registered — a Dubbo Java peer sending it gets SERIALIZATION_ERROR; either implement it or remove the constant. Failover retries on UNAVAILABLE without an idempotency gate, so non-idempotent unary calls can double-execute on transport blips.

@cnzakii
cnzakii force-pushed the python-native-rebuild branch from a504612 to c621758 Compare November 24, 2026 14:10
Replace the previous implementation with a new one built on asyncio and
AnyIO, with uvloop optional, for Python 3.11 to 3.14:

- the Triple protocol over HTTP/2, interoperable with gRPC, and over
  HTTP/3 with the http3 extra, and the Dubbo protocol with Hessian 2,
  both in the default installation;
- one port that serves HTTP/1.1, HTTP/2 and HTTP/3, where methods also
  answer plain HTTP calls with JSON, at default or declared routes, with
  CORS and an OpenAPI document;
- application-level and interface-level service discovery on ZooKeeper
  and Nacos, with metadata services and reports, and configuration
  centers;
- clusters, load balancers, condition and tag routers, configurators and
  filters, as extension points loaded by entry points;
- configuration from code, files and environment variables;
- the protoc plugin that generates service stubs;
- samples, from a first call to a small shop of services behind
  FastAPI, an agent of Pydantic AI whose tools are services, and calls to
  and from Dubbo Java and Dubbo Go, each with a README and run by the
  tests;
- end-to-end benchmarks of servers on one core and on eight, beside Dubbo
  Java, Dubbo Go and the gRPC libraries of Python, and of a Dubbo Python
  consumer;
- unit and integration tests on a virtual clock, CI on GitHub Actions,
  and release candidates for the release manager to sign.

Extras add the ZooKeeper and Nacos clients, the YAML and properties
configuration formats, uvloop, protoc, JSON for types other than
protobuf messages, and HTTP/3.
@cnzakii
cnzakii force-pushed the python-native-rebuild branch from c621758 to b6277fb Compare November 24, 2026 14:51
@cnzakii

cnzakii commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Thanks for the substantial work. I reviewed and ran this locally before commenting.

Verified green: uv sync --locked --all-extras; pytest tests/unit (1404 passed), pytest tests/integration -m "not zookeeper and not nacos and not samples" (552 passed); ruff check/format/ty check; the 01_hello_world sample end-to-end; 2070 tests confirmed via --collect-only; CI matrix green including the ZooKeeper/Nacos integration jobs. The Triple gRPC wire implementation (5-byte framing, grpc-timeout units, trailer-only responses, grpc-status-details-bin, compression negotiation) matches the gRPC HTTP/2 spec, and the Dubbo protocol header/body layout matches Dubbo Java's documented structure.

Requesting changes on four points:

  1. Dependency governance. The entire wire stack hard-depends on ngh2 (HTTP/2), h11r (HTTP/1.1) and hessian2 (serialization), plus ngquic for the http3 extra — all published under the PR author's account, created between July and November 2026 (ngquic two days before this PR), each with a single maintainer and no third-party adoption record. Established alternatives exist (h2, h11, aioquic); if the choice is a deliberate performance/design bet on Sans-I/O + native cores, please document it (ADR) with the benchmark evidence, and get explicit PMC sign-off on the dependency set. Additionally, NOTICE carries no third-party attribution while the wheels bundle libnghttp2, ngtcp2, nghttp3 and aws-lc — the release manager will likely require a DEPENDENCIES/NOTICE update before any release.
  2. Default security posture. By default a provider exposes every exported method over plain HTTP JSON (triple.rest.enabled defaults to true) and to $invoke generic calls over gRPC and Dubbo, with no built-in authentication (TokenFilter only activates when a token URL parameter is present) and TLS off. That is fine for samples but dangerous as a default. Please either invert the defaults (REST off by default, generic invoke gated) or add a prominent security note to the README/Configuration docs stating the exact unauthenticated surface a default deployment exposes.
  3. Claims I could not reproduce from the repo. (a) "94% line and branch coverage" — the new pyproject.toml has no coverage configuration and CI does not run coverage, so the number is unverifiable; please add a coverage job or drop the figure. (b) The "tests at scale" bullet (providers killed mid-call, rolling releases, registry outages) has no corresponding tests in the repository — the in-tree failure tests exercise graceful aclose() only. Either commit the harness or scope the claim.
  4. Migration. The public API is fully replaced (Client/Server are gone, Python ≥3.11, sync→async), which the PR acknowledges, but there is no migration guide; users of the previous release have only the new quick start and samples to reverse-engineer from. A MIGRATION.md mapping old → new would substantially reduce the break's cost.

Minor: SERIALIZATION_IDS advertises fastjson2 (id 23) but no fastjson2 serialization is registered — a Dubbo Java peer sending it gets SERIALIZATION_ERROR; either implement it or remove the constant. Failover retries on UNAVAILABLE without an idempotency gate, so non-idempotent unary calls can double-execute on transport blips.

Thanks for the review.

  1. Dependencies. Dubbo drives the protocol engines from asyncio. The new ngh2 and optional ngquic bindings reuse libnghttp2, ngtcp2, and nghttp3, engines used by Node.js and curl. h11r uses httparse, and hessian2 has a Rust codec. Published component benchmarks peak at 38.6× for HTTP/1.1, 29.4× for HTTP/2, and 80.4× for raw QUIC versus aioquic in memory at concurrency 64. The four packages use MIT, an ASF Category A license. The inspected wheels include the bundled libraries’ license texts. HTTP/1.1 · HTTP/2 · QUIC/HTTP/3 · Hessian2 interop · ASF policy
  2. Defaults. Java 3.3.7 enables Triple REST by default. Should Python keep the same default, or should providers explicitly enable REST? Java and Go accept ordinary generic calls by default. In Python, token authentication and TLS require configuration. Java REST defaults · Java generic filter · Go provider defaults
  3. Tests. The local unit and integration run passed 1,961 tests, with 94.77% line and 87.11% branch coverage after excluding generated code. The external Linux harness recorded 32,400 successful calls across 24 scale runs. It also exercised provider termination, rolling releases, and registry outages.
  4. Migration. This is a breaking rewrite. The synchronous Client and Server APIs give way to the async Dubbo API on Python 3.11+.
  5. Fastjson2 and retries. ID 23 identifies Fastjson2 JSONB in the error message. The native Dubbo codec is Hessian2. Failover can replay a non-idempotent write, and retries=0 disables retries for that method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] [Dubbo-python] Rebuild Dubbo Python as a Python-native framework

2 participants