Architecture: Centralized Personal Information Store

By Engineering Team•October 1, 2026•7 min read

This is the architecture behind the decisions recorded in ADR-00018 (row-based attribute model), ADR-00019 (dedicated service vs. per-service duplication), ADR-00020 (shared core-lib implementation), and ADR-00021 (PostgreSQL vs. MongoDB), satisfying the requirements in BRD-009 and SR-010.

Diagram

Centralized Personal Information Store — pii-service component topology, its seven real consumers, and the generic attribute CRUD vs. address-snapshot data flows

Components

Component Language / Runtime Role
pii-service Rust gRPC-only encrypted attribute store — UpsertAttributes/GetAttributes/DeleteAttributes for the generic EAV model, CreateAddressSnapshots/GetAddressSnapshots for the address-dedup model (FR-01).
rust-lang-core-lib’s domain::encrypt/service::encrypt/repository::encrypt Rust (shared library) Owns the generic RowAttributeService (validate → AES-256-GCM encrypt/decrypt → repository call → audit-log write), shared byte-for-byte with pci-service (FR-02, FR-03, FR-12, NFR-02).
PostgreSQL — "pii-service" schema PostgreSQL user_pii_attributes (generic EAV rows), address_snapshots (dedup parent, unique (tenant_id, created_user_id, content_hash)), address_snapshot_attributes (encrypted child rows, reusing the shared write path), row_attribute_audit_log (FR-02, FR-06, FR-07, FR-12).
inventory-service Go Writes warehouse contact details under entity_type="warehouse" on CreateWarehouse, with a best-effort compensating delete of its own row if the PII write fails (FR-05; gap — see TD-01).
user-secure-engine Rust Writes/reads profile fields (full_name, email, phone_number, dob, gender) under entity_type="user_personal" on account init and profile update (FR-05).
notification-service Rust Same PII client pattern as user-secure-engine, wired into a live UserService gRPC surface — its caller_service attribution is currently incorrect (FR-04; gap — see TD-02).
user-preference-service Go Write-only: pushes a customer’s shipping/billing address bodies under entity_type="user_address" on every address add/update, never storing address content in its own Mongo collection (FR-05).
order-service Go Reader of entity_type="user_address" (resolving a shopper’s saved address at checkout) and writer/reader of the separate "address.xxx"-prefixed attribute-key namespace via CreateAddressSnapshots/GetAddressSnapshots — stores only AddressSnapshotRef{address_type, snapshot_id} in its own checkout-saga data, never raw address content (FR-05, FR-06).
shipment-service Go Reads one address snapshot at a time (GetAddressSnapshot, singular) for fulfillment/label generation (FR-10).
shop-service Go Reads address snapshots in batch (GetAddressSnapshots, plural) for order detail/display (FR-10).

End-to-end flow (A) — generic attribute write and read

This flow covers any of the three non-address writer/reader paths (inventory-service’s warehouse contact, user-secure-engine’s/notification-service’s user_personal profile fields, user-preference-service’s user_address bodies).

  1. The consuming service performs its own local write first (e.g. inventory-service inserts the new warehouse’s Postgres row) (NFR-03).
  2. It calls pii-service’s UpsertAttributes with caller_service, a fresh transaction_id, its own chosen entity_type ("warehouse" / "user_personal" / "user_address"), entity_id, and the attribute list — tenant_id/user_id/role travel as gRPC metadata, never in the payload (FR-01, FR-02, FR-04, FR-05, FR-11, NFR-07).
  3. rust-lang-core-lib’s shared RowAttributeService validates the input, encrypts each plaintext_value with AES-256-GCM and a fresh random nonce, and persists it to user_pii_attributes under the "pii-service" schema (FR-02, FR-03, NFR-01, NFR-02).
  4. The same call writes one row_attribute_audit_log entry recording caller_service, transaction_id, action, entity_type, entity_id (FR-12).
  5. If step 2/3 fails after step 1 succeeded, the caller compensates by rolling back its own local write — inventory-service’s CreateWarehouse is the only verified implementation of this today, and its compensating delete is itself best-effort (NFR-03; gap — see TD-01).
  6. A later read calls GetAttributes with the known requested_attributes key list; pii-service decrypts only inside this call and returns a decrypted_attributes map — a decrypted value is never written to a log line (FR-03).

End-to-end flow (B) — address snapshot at checkout

  1. At checkout, order-service calls GetAttributes against entity_type="user_address" to resolve the shopper’s saved address — the same namespace user-preference-service writes to (FR-02, FR-05).
  2. order-service builds its own "address.xxx"-prefixed attribute set for the shipping and/or billing address and calls CreateAddressSnapshots with one address block per type (FR-06).
  3. For each block, pii-service sorts its attributes by attribute_key, computes a SHA-256 hex digest of key=trimmed_lowercased_value\n per attribute, and combines them into one content_hash (FR-07).
  4. It looks up (tenant_id, created_user_id, content_hash) in address_snapshots: a match reuses the existing snapshot_id (is_new_snapshot: false); no match inserts a new address_snapshots row and writes its attributes to address_snapshot_attributes via the same shared encrypted write path as Flow A, with entity_type hardcoded to "address" and entity_id set to the new snapshot’s UUID (FR-06, FR-07, FR-08).
  5. A concurrent call racing for the same (tenant_id, created_user_id, content_hash) has its unique-constraint violation detected; the losing request re-fetches the winning row’s snapshot_id instead of writing orphaned child attribute rows (FR-09).
  6. pii-service returns snapshot_results[{address_type, snapshot_id, is_new_snapshot}]; order-service persists only AddressSnapshotRef{address_type, snapshot_id} on its checkout-saga data — never the raw address content (FR-06).
  7. Later, shipment-service resolves one snapshot at a time (GetAddressSnapshot) for fulfillment/label generation, and shop-service resolves snapshots in batch (GetAddressSnapshots) for order detail/display — both decrypt via the "address.xxx" keys order-service originally wrote, bypassing the generic GetAttributes read path (which requires a known key list) in favor of a local lookup-by-entity_id plus a second, directly-instantiated cipher (FR-10).
  8. Every call in this flow — including a snapshot lookup that reuses an existing snapshot via dedup — writes its own row_attribute_audit_log entry the same way Flow A’s step 4 does (FR-12).