Postgres
async with postgres.transaction(): | Runs the queries inside it as one transaction |
UPDATE t SET ... WHERE ... RETURNING col | Returns the rows it changed, or [] if WHERE matched none |
SELECT ... FOR UPDATE | Locks the rows it reads until the transaction ends. Other writers and FOR UPDATEs wait |
now() | The current transaction's start time |
now() + interval '10 minutes' | A time 10 minutes from now. make_interval(mins => n) for a variable n |
Each run fills seats with 2,400 free seats: id, section, and price_cents.
Advisory locks
Locks on a number you choose rather than on rows.
pg_advisory_xact_lock(key) | Waits for the lock, and holds it until the transaction ends |
hashtext('104-F-12') | Turns text into a number, for use as a key |
Redis
await redis.set(key, value, ...) | Sets a key, with the options below. Returns True, or None if an option stopped it |
set option | |
|---|---|
nx=True | Only set the key if it doesn't exist |
ex=seconds | Delete the key after seconds |
Python time
datetime.now(timezone.utc) | The current time, in UTC |
dt + timedelta(minutes=10) | 10 minutes later |
dt.isoformat() | "2026-10-24T19:42:00+00:00". A datetime can't go in json as is |
Postgres returns timestamps as ISO 8601 text, like "2026-10-24T19:42:00.000Z". The checks move the clock forward to test expiry, and Python's time follows it, as do now() and Redis expiry.
Python · 52 linesStarter code · Ctrl/⌘ + Enter to run
SystemBroke
No runs yet.
Run the simulation to send this kata's traffic to your code. Hidden checks grade what it does.