Lightweight DB-backed coordination primitive with leases and fencing tokens
Project description
Sentinel
A lightweight coordination primitive for backend systems.
Features
- DB-backed leases
- Fencing tokens (prevents stale worker writes)
- Simple API (
acquire,heartbeat,release,lease)
Example
import sentinel
with sentinel.lease(conn, "order_123", ttl_ms=5000, get_conn=get_conn):
process_order()
API
acquire
result = sentinel.acquire(conn, key, ttl_ms=5000)
Returns:
acquired(bool)owner_id(str)expires_at(timestamp)fencing_token(int)
heartbeat
result = sentinel.heartbeat(conn, key, owner_id, ttl_ms=5000)
Returns:
extended(bool)
release
result = sentinel.release(conn, key, owner_id)
Returns:
released(bool)
lease (recommended)
with sentinel.lease(conn, key, ttl_ms=5000, get_conn=get_conn):
do_work()
Handles:
- acquire
- automatic heartbeat
- release on exit
Fencing Tokens (Important)
Each acquire returns a monotonically increasing fencing token.
To use fencing tokens safely:
- Store
fencing_tokenin your application data - Include a condition in all writes
Example:
UPDATE orders
SET status = 'paid', fencing_token = %s
WHERE id = %s AND fencing_token <= %s;
This ensures:
- stale workers cannot overwrite newer ones
- race conditions are safe
Use Cases
- Background workers
- Job queues
- Payment processing
- Idempotent APIs
Status
⚠️ Beta (v0.1.0)
Limitations
- No retries yet
- No async support
- TTL tuning required
- External side effects must be handled separately
Philosophy
Sentinel does not eliminate race conditions. It makes them safe.
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
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 sentinel_coordination-0.1.1.tar.gz.
File metadata
- Download URL: sentinel_coordination-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6086f101815904a7d107702d20b4cf2ff9dbf96f24dcac0be19bc4b49d2dbe72
|
|
| MD5 |
b543d83b3675d001a4df46d75b36a0b6
|
|
| BLAKE2b-256 |
5c948cd8db09fe5e8287db4a1cfa83e66e6629eb08c89251fdc72115d6661c9b
|
File details
Details for the file sentinel_coordination-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sentinel_coordination-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05d21fb7c12b544162829ab2bf176f5e85dc702cb8d8afe70d786a1eacf866df
|
|
| MD5 |
aed2104f9d7f94a0868a238824909fae
|
|
| BLAKE2b-256 |
cf0135389dd9a185bb787b3f437f43d0d1477f16709abdf553b38950e6b31614
|