Engineering decisions
Enforce access in the database, not in every query
Problem: Application-level tenant filters hold only until someone writes one new
endpoint under deadline without reading the threat model.
Approach: 191 PostgreSQL row-level security policies evaluated against actor
identifiers set on the transaction, driven by a non-bypass app_user role with a
boot-time refusal if misconfigured. A forgotten filter returns zero rows.
Tradeoff: Policy SQL requires careful migration reviews and tests must run as
app_user, paying engineering discipline upfront for a database-level guarantee.
Prevent double bookings with a lock, not a check
Problem: Read-then-write availability checks fail under concurrent taps, and
unique keys alone cannot express overlapping appointment intervals.
Approach: Shared pure-function slot generation plus a transaction-scoped
advisory lock (pg_advisory_xact_lock) keyed to practitioner and time window,
paired with effective-dated fee snapshots.
Tradeoff: Serializes writes per practitioner window only, verified by an
integration test executing concurrent database transactions.
Publish events through a Postgres outbox instead of adding Kafka
Problem: Dual-writing to a DB and an external message broker creates the
"committed but unpublished" split-brain failure.
Approach: Write outbox events in the same transaction as business mutations and
drain them via SELECT ... FOR UPDATE SKIP LOCKED, reusing available_at
for scheduled appointment reminders.
Tradeoff: Polling introduces slight latency and does not target Kafka-scale
throughput, which is explicitly documented as an architectural decision record.