Qx multi-region: tenant home-region resolution, write routing, and cross-region event replication
Project description
qx-regions
Multi-region support for Qx services: tenant home-region resolution, write routing with automatic redirect, and cross-region event replication.
Concepts
- Home region — the Postgres write primary for a given tenant. All writes must reach the home region; reads can come from any local replica.
- RegionResolver — maps
tenant_id → region_name. UseStaticRegionResolverfor tests/simple deployments,DbRegionResolverfor production. - RegionRouter — given a request's tenant and path, returns a redirect URL when the current region is not the tenant's home region.
- RegionReplicator — background worker that forwards published outbox events to a remote region's NATS cluster (application-level fallback when JetStream mirroring is not configured).
Usage
from qx.regions import (
RegionConfig,
RegionRouter,
StaticRegionResolver,
RegionReplicator,
include_region_tables,
)
# Startup
config = RegionConfig() # reads QX_REGION__NAME, QX_REGION__URLS
resolver = StaticRegionResolver( # or DbRegionResolver for production
{"tenant-abc": "eu-west-1"},
default=config.name,
)
router = RegionRouter(resolver, config)
# Per-request — redirect writes to the home region
redirect = await router.get_redirect_url(tenant_id, request.path)
if redirect:
return Response(status=307, headers={"Location": redirect})
# Cross-region replication worker
replicator = RegionReplicator(
engine, remote_publisher,
target_region="eu-west-1",
events_table=events_t,
checkpoints_table=checkpoints_t,
)
await replicator.run() # blocks; call replicator.stop() from signal handler
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
qx_regions-1.0.0.tar.gz
(7.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qx_regions-1.0.0.tar.gz.
File metadata
- Download URL: qx_regions-1.0.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dea36109e3b774c7d8273203481a4cebb5ea8bbdb6fefe52bd75d631712c8b1
|
|
| MD5 |
682bc7c58d448cbfc513ae100b3749e3
|
|
| BLAKE2b-256 |
273f08fdf674b3a6085917fb42a5aff2295846b28d3c1d23b8328b73d9fdc637
|
File details
Details for the file qx_regions-1.0.0-py3-none-any.whl.
File metadata
- Download URL: qx_regions-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
377e74b49c950ba8af693a279282a0dc76cc302064b5bca1c88b7bd979cd5410
|
|
| MD5 |
e1a59afa33fd039425df655fb9eac9e4
|
|
| BLAKE2b-256 |
cf3a57831df351f02631bf644a81b6553efbe17c79a77beab9853aa9e32bddd2
|