SR-010 — Centralized Personal Information Store: System Requirements

By Engineering Team•October 1, 2026•7 min read
Metadata Details
System Name pii-service — Centralized Personal Information Store
Document ID SR-2026-PII-001
Author Engineering Team
Status Approved

Traces back to BRD-009 — Centralized Personal Information Store.


Functional Requirements

Attribute Storage & Retrieval

  • FR-01 (gRPC-Only Surface): pii-service MUST expose UpsertAttributes, GetAttributes, and DeleteAttributes over gRPC only — it MUST NOT expose any HTTP/REST surface, and no other service MUST be able to query its PostgreSQL database directly.
  • FR-02 (Entity-Attribute-Value Keying): every stored attribute MUST be keyed by (tenant_id, entity_type, entity_id, attribute_key), persisted in the user_pii_attributes table under the "pii-service" schema, with a unique index on that four-part key.
  • FR-03 (Encryption At Rest): every plaintext_value MUST be encrypted with AES-256-GCM, with a fresh random nonce per value, before being written to user_pii_attributes — decryption MUST happen only inside GetAttributes, and a decrypted value MUST never be written to a log line.
  • FR-04 (Caller Attribution): every UpsertAttributes/GetAttributes/DeleteAttributes request MUST carry a non-empty caller_service and transaction_id in its payload — pii-service has no other mechanism to attribute a call to its originating system or business operation.
  • FR-05 (Consumer-Owned entity_type Namespace): entity_type is a free-text value chosen by each consuming service ("warehouse", "user_personal", "user_address" are the values in use today) — adding a new entity type requires no code change inside pii-service itself.

Address Snapshot & Dedup

  • FR-06 (Dedicated Address Snapshot Model): shipping/billing address content submitted via CreateAddressSnapshots MUST be stored in two dedicated tables (address_snapshots, address_snapshot_attributes) rather than the generic user_pii_attributes model, since an address snapshot has no caller-owned entity_id to key by until after deduplication occurs.
  • FR-07 (Content-Hash Deduplication): for each submitted address block, pii-service MUST sort its attributes by attribute_key, compute a SHA-256 hex digest of key=trimmed_lowercased_value\n per attribute, and combine them into one content_hash; a lookup on (tenant_id, created_user_id, content_hash) that finds an existing address_snapshots row MUST reuse its snapshot_id (is_new_snapshot: false) instead of writing a new one.
  • FR-08 (Per-User Dedup Scope): deduplication MUST be scoped to (tenant_id, created_user_id) — two different users in the same tenant who submit an identical physical address MUST NOT collide into the same snapshot.
  • FR-09 (Race-Safe Snapshot Insert): a CreateAddressSnapshots call that races another concurrent call for the same (tenant_id, created_user_id, content_hash) MUST detect the resulting unique-constraint violation, re-fetch the winning row’s snapshot_id, and use it — the losing request MUST NOT write its own orphaned child attribute rows.
  • FR-10 (Snapshot Retrieval By ID): GetAddressSnapshots MUST resolve each {snapshot_id, address_type} lookup to its decrypted attributes without requiring the caller to know the attribute-key set in advance, and MUST pass address_type through unchanged from the request without validating it.

Multi-Tenancy & Auth Propagation

  • FR-11 (gRPC Metadata Auth): tenant_id, user_id, and role MUST be read exclusively from gRPC metadata, extracted via rust_lang_core_lib::auth::extract_auth_claims — a request missing any of the three MUST be rejected with tonic::Status::unauthenticated, and these values MUST NEVER be read from the request payload.

Audit Trail

  • FR-12 (Per-Call Audit Logging): every UpsertAttributes (Write), GetAttributes (Read), and DeleteAttributes (Delete) call — including a snapshot lookup that reuses an existing snapshot via dedup — MUST write one entry to row_attribute_audit_log recording caller_service, transaction_id, action, entity_type, and entity_id.

Non-Functional Requirements

Security

  • NFR-01 (Per-Service Encryption Key): each of pii-service/pci-service MUST use its own AES-256-GCM key (PII_ENCRYPTION_KEY / PCI_ENCRYPTION_KEY), sourced from an environment variable, never hardcoded or shared across services.
  • NFR-02 (Shared Implementation, Isolated Schema): pii-service and pci-service MUST share the same domain::encrypt/service::encrypt/repository::encrypt implementation from rust-lang-core-lib, while each persisting to its own PostgreSQL schema ("pii-service" vs. "pci-service") — no row of one service’s data MUST ever be reachable through the other’s schema.

Consistency & Cross-Service Transactions

  • NFR-03 (Caller-Owned Compensation): because pii-service participates in no distributed transaction with its callers, a consuming service that writes its own local row before calling UpsertAttributes MUST compensate (roll back its own local write) if the pii-service call fails. (Gap — inventory-service’s CreateWarehouse is the only verified implementation of this today, and its own compensating delete is best-effort: a failure of the compensating DeleteWarehouseByID call is only logged, not retried, leaving a warehouse row with no PII attributes. Tracked as technical debt — see Technical Debt — Centralized Personal Information Store Gaps, TD-01.)

Caller Attribution Integrity

  • NFR-04 (Accurate caller_service Attribution): caller_service sent by any consumer MUST identify the actual calling service, never a copy-pasted value from a different service’s integration code. (Gap — notification-service’s infra/pii_client.rs is a verbatim copy of user-secure-engine’s client, including a hardcoded CALLER_SERVICE = "user-secure-engine" constant, and is wired into a live gRPC server (UserServiceServer) inside notification-service’s own app_config.rs — every resulting row_attribute_audit_log entry misattributes the real caller. Tracked as technical debt — see Technical Debt — Centralized Personal Information Store Gaps, TD-02.)

Namespace Governance

  • NFR-05 (entity_type Collision Avoidance): two unrelated consuming services SHOULD NOT be able to pick the same entity_type value for unrelated data. (Gap — entity_type is free text with no central registry or compile-time enforcement; today’s values ("warehouse", "user_personal", "user_address") avoid collision only by convention. Tracked as technical debt — see Technical Debt — Centralized Personal Information Store Gaps, TD-03.)

Observability

  • NFR-06 (Span Hygiene): every public pii-service method MUST use #[tracing::instrument] with claims/struct parameters in skip(), never auto-captured, per 04-observability-and-tracing’s Rust instrumentation rule.
  • NFR-07 (Metadata Propagation to Callers): every outbound call to pii-service MUST carry tenant_id/user_id/role as gRPC metadata sourced from the calling service’s own AuthClaims, never re-derived.