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.1.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.1.0.tar.gz.
File metadata
- Download URL: qx_regions-1.1.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 |
94eada473b2b1c54c25ca37437b81d08691bfd3874352332892f13069e389c6c
|
|
| MD5 |
60a35106d3222d30fd4b99ac23dc9ffe
|
|
| BLAKE2b-256 |
e2869af765b275a7ca088eac53e5bc47816ec723984f1a66329c0d5e2336ae99
|
File details
Details for the file qx_regions-1.1.0-py3-none-any.whl.
File metadata
- Download URL: qx_regions-1.1.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 |
3bcb16b1baf51fd86fd4dfb3e2ec1ed5248184a668dde30e7b8a787ba421656a
|
|
| MD5 |
a3660c2e3647980f3d0b915c75a55674
|
|
| BLAKE2b-256 |
457f259567292524ea66a3262b0ba9792600d6f32fcd1f537ea86901202bc7d9
|