pii-service — Centralized Encrypted Personal Information Store

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

Responsibility

pii-service is the central, tenant-isolated store for any personal data another microservice needs to attach to one of its own records, so no other service has to build its own protection for that data.

  • Generic encrypted attribute store — UpsertAttributes/GetAttributes/DeleteAttributes, keyed by (tenant_id, entity_type, entity_id, attribute_key). entity_type is a free-text namespace chosen by the calling service ("warehouse", "user_personal", "user_address" are the values in use today) — adding a new one requires no code change here.
  • Address snapshot & dedup — CreateAddressSnapshots/GetAddressSnapshots, a dedicated model (not the generic EAV one) solving a real key-ordering gap: an address has no caller-owned entity_id to key by until after deduplication occurs. Content-hash dedup is scoped to (tenant_id, created_user_id).
  • Encryption at rest — every plaintext_value is AES-256-GCM-encrypted with a fresh random nonce before insert; decryption happens only inside a Get* call, and a decrypted value is never written to a log line.
  • Per-call audit trail — every write, read, or delete (including a dedup-reused snapshot lookup) writes one row_attribute_audit_log entry recording caller_service, transaction_id, action, entity_type, entity_id.
  • gRPC-only, no direct database access from outside this service — no HTTP/REST surface exists, and no other service may query its PostgreSQL schema directly.

Tech Stack

Concern Choice
Language Rust
gRPC tonic server only — no outbound gRPC client, no REST/HTTP surface
Data store PostgreSQL (SeaORM), schema "pii-service" — same shared Postgres instance as pci-service/user-secure-engine, isolated by schema
Shared logic rust-lang-core-lib’s domain::encrypt/service::encrypt/repository::encrypt — identical implementation consumed by pci-service; see ADR-00020
Template @templates/rust-postgres-microservice
Encryption AES-256-GCM, one key per service (PII_ENCRYPTION_KEY, 32-byte base64 env var)

Ports

Gateway gRPC (host → container) Service Name
— (internal only, no HTTP/Nginx route) 50054 → 50053 pii-service

pii-service does not appear in the central Port Matrix (see the deployment & local infrastructure standard) — the mapping above is read directly from development/docker-compose.yml, not from that table.

Data

Table Purpose
user_pii_attributes Generic EAV rows, unique index on (tenant_id, entity_type, entity_id, attribute_key).
address_snapshots Dedup parent table, unique index on (tenant_id, created_user_id, content_hash).
address_snapshot_attributes Encrypted child rows, shaped like user_pii_attributes, written via the same shared RowAttributeService path with entity_type hardcoded to "address" and entity_id set to the snapshot’s UUID.
row_attribute_audit_log One row per UpsertAttributes/GetAttributes/DeleteAttributes/snapshot call — same table name and shape as pci-service’s own, different schema.

Real Consumers

Consumer Language Usage
inventory-service Go Writes warehouse contact details, entity_type="warehouse", write-only.
user-secure-engine Rust Writes/reads account profile fields, entity_type="user_personal".
notification-service Rust Same client pattern as user-secure-engine, wired into its own live UserService gRPC surface.
user-preference-service Go Write-only — pushes address bodies, entity_type="user_address", on every add/update; never stores address content in its own Mongo collection.
order-service Go Reads entity_type="user_address" at checkout, then writes/reads the separate "address.xxx"-prefixed key namespace via CreateAddressSnapshots/GetAddressSnapshots; stores only a snapshot_id reference, never raw address content.
shipment-service Go Reads one address snapshot at a time (GetAddressSnapshot) for fulfillment/label generation.
shop-service Go Reads address snapshots in batch (GetAddressSnapshots) for order detail/display.

Implementation Notes

  • user_pii_attributes was originally named pii_attributes — renamed via a data-preserving ALTER TABLE ... RENAME TO migration, not a drop/recreate, so any already-applied environment keeps its rows.
  • The domain/service layer (RowAttribute* types, RowAttributeService, the AES-256-GCM cipher) is shared with pci-service entirely through rust-lang-core-lib — only the concrete SeaORM entity (table/schema name, fixed at compile time) and the gRPC handler are local to each service. See ADR-00020 for why this split exists.
  • pii-service is deliberately a dedicated, gRPC-only service rather than logic duplicated into each consumer — see ADR-00019. Its row-based attribute model and PostgreSQL data store are their own decisions — see ADR-00018 and ADR-00021.
  • GetAddressSnapshots bypasses the shared RowAttributeService::get_attributes read path (which requires a non-empty, caller-known attribute-key list) via a local find_all_by_entity lookup and a second, directly-instantiated AesGcmCipher — a deliberate, documented exception, not a parallel reimplementation of the cipher logic.
  • notification-service’s integration is a verbatim copy of user-secure-engine’s client code, including a hardcoded caller_service value that still reads "user-secure-engine" — every audit-log entry notification-service produces today misattributes its real origin. See Technical Debt — Centralized Personal Information Store Gaps, TD-02.
  • entity_type is free text with no central registry or server-side collision check — today’s three values avoid collision only by convention between the teams that picked them. See TD-03.
  • pii-service participates in no distributed transaction with any caller — a caller that writes its own row before calling UpsertAttributes is responsible for compensating if the PII call fails, and that compensation is currently best-effort only in its one verified implementation (inventory-service). See TD-01.

Architecture overview: Architecture: Centralized Personal Information Store.