Files
mtusi2026lab3/docs/archive/implementation.md

16 lines
2.3 KiB
Markdown

# Implementation plan and boundaries
Archived: this inherited lab2 plan is retained as historical context only. The completed lab3 implementation, results and limitations are documented in ../../REPORT.md; startup instructions are in ../../RUN.md.
This repository carries our lab1 domain, pagination, HTTP/error handling, bounded queue and shutdown code into the original lab2 skeleton. The lab1 memory adapter and its obsolete HTTP identity tests are not carried forward.
PostgreSQL is authoritative for users, passwords, sessions, chats, membership and messages. Valkey caches immutable public profiles for 60 seconds; no chat/message/session cache is used. Authentication always reads the session from PostgreSQL, and cache failure falls back to PostgreSQL within an 80 ms budget. Logout deletes the persisted token hash. Cache contents contain no password or bearer token.
Transactions: chat allocation + chat row + membership; sender quota + message; session owner lock + expiry cleanup + session insertion. PostgreSQL constraints enforce username uniqueness and foreign keys. Maximums: 1000 created chats and 1,000,000 messages per owner; 100 unexpired sessions. No user data is silently deleted. The history index covers `(chat_id,created_at,id)` and queries fetch only `limit+1` rows. Keyset traversal is not a snapshot; writes whose wall-clock timestamps fall before a consumed cursor can be missed during concurrent traversal.
Argon2id uses a random 16-byte salt, 32 MiB, two iterations, one lane, 32-byte result. Tokens use 32 random bytes; PostgreSQL stores only SHA-256 of the token. SHA-256 is appropriate for high-entropy tokens, not passwords. The API gate bounds concurrent KDF calls to four. PostgreSQL pool: eight connections, statement timeout 2 s, lock timeout 1 s, connect timeout 1 s; request context 5 s.
Readiness checks PostgreSQL. Valkey is optional to safe operation; its absence is observable through cache hit statistics and failure tests, not an anonymous-authentication fallback. HTTP is bound to localhost and uses only generated synthetic data.
Research: compare history queries over at least 100,000 skewed messages; restore a backup into a new database, compare row counts and selected message bytes. See `REPORT.md` for actual results; planned experiments are not evidence.