跳到正文
DEV Community· Bright Machawira·· 1 小時前AI 評分43

在開發功能前先定下不可逆決策:Erudyt 的四項數據庫選擇

Deciding the irreversible first: four database choices I made before writing any features

AI 導讀

Erudyt 是以 FastAPI 和 PostgreSQL 建構的多租戶學校管理與分析平台,開發功能前先確定了四項難以低成本更改的數據庫選擇:UUID 主鍵、軟刪除、數據庫層租戶隔離,以及自行負責 JWT 身份驗證。這些選擇各有成本,包括較大的儲存與索引、查詢及清除數據的額外要求,以及長期承擔身份驗證責任。

正文

Bright Machawira

Most engineering decisions can be revisited. A small number cannot, because data accumulates on top of them. When I began building Erudyt, a multi-tenant school management and analytics platform on FastAPI and PostgreSQL, I listed the decisions I would not be able to change cheaply and made them first.

  1. UUID primary keys
    Sequential integers are guessable, which weakens any endpoint that exposes an id, and they collide when records from separate tenants are merged. UUIDs cost more storage and larger indexes, which I accepted. Changing key type later means rewriting every foreign key that references it.

  2. Soft deletes
    A student's results are a historical record. Soft deletion preserves that history, but it has costs: every query needs a filter, unique constraints must account for deleted rows, and data protection obligations mean you still need a deliberate, audited purge path. I designed that path rather than leaving it for later.

  3. Tenant isolation at the database
    Application code will eventually contain a mistake, and in a multi-tenant system a mistake can expose one school's records to another. PostgreSQL row-level security enforces isolation at the data layer. The caveat is that a policy no one tests is only an intention, so isolation tests belong in the suite from the beginning.

  4. Owning authentication
    I implemented JWT authentication in FastAPI to avoid vendor lock-in. This trades convenience for responsibility: hashing, token lifetime, rotation and revocation become my problem permanently. It suits a team prepared to carry that, and not one hoping to avoid it.

Why it matters beyond engineering
Zimbabwe's Cabinet approved a National AI Charter this week, built on transparency, inclusion and human-centred principles. Governance is arriving alongside adoption, and systems that hold children's records will increasingly be asked to explain how they work. Early structural decisions make that explanation straightforward.

The rule
Before the first table exists, list what you could not change in two years, and spend your slowest effort there. Move quickly on everything else.

來源:DEV Community · dev.to