pci-service — Centralized Encrypted Card Data Store
By Engineering Team•October 10, 2026•4 min read
Responsibility
pci-service is the central, tenant-isolated store for card-data attributes (card token, last 4 digits, brand) — the PCI-scoped counterpart to pii-service’s personal-data store, sharing the same underlying implementation rather than a hand-maintained duplicate.
- Generic encrypted attribute store — the same
UpsertAttributes/GetAttributes/DeleteAttributesEAV surface aspii-service, keyed by(tenant_id, entity_type, entity_id, attribute_key). - Encryption at rest — every
plaintext_valueis AES-256-GCM-encrypted with a fresh random nonce before insert, decrypted only inside aGet*call, keyed by its ownPCI_ENCRYPTION_KEYenv var (never shared withpii-service’s key). - Per-call audit trail — every write/read/delete writes one
row_attribute_audit_logentry (caller_service,transaction_id,action,entity_type,entity_id), same shape aspii-service’s table, different schema. - gRPC-only, no direct database access from outside this service — no HTTP/REST surface; 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 "pci-service" — same shared Postgres instance as pii-service/user-secure-engine, isolated by schema, one schema per owning microservice |
| Shared logic | rust-lang-core-lib’s domain::encrypt/service::encrypt/repository::encrypt — identical implementation consumed by pii-service; only the concrete SeaORM entity and gRPC handler are local to each service |
| Template | @templates/rust-postgres-microservice |
| Encryption | AES-256-GCM, PCI_ENCRYPTION_KEY (32-byte base64 env var) |
| Migration tracking | pci_service_migrations — a service-scoped table, not the shared seaql_migrations table |
Ports
| Gateway | gRPC (host → container) | Service Name |
|---|---|---|
| — (internal only, no HTTP/Nginx route) | 50057 → 50053 |
pci-service |
50054/50055 are already taken by pii-service/shop-service on the host side — pci-service’s host mapping was deliberately picked to avoid that collision; the container-internal port (50053) is identical to every other Rust gRPC-only service’s convention.
Data
| Table | Purpose |
|---|---|
user_pci_attributes |
Generic EAV rows, unique index on (tenant_id, entity_type, entity_id, attribute_key) — same shape as pii-service’s user_pii_attributes, card-data values only (card token, last 4, brand). |
row_attribute_audit_log |
One row per UpsertAttributes/GetAttributes/DeleteAttributes call — same table name and shape as pii-service’s own, different schema. |
Implementation Notes
- The entire domain/service layer (
RowAttribute*types,RowAttributeService, the AES-256-GCM cipher) is shared withpii-servicethroughrust-lang-core-lib— only the compile-time macro attributes (table_name/schema_nameon the SeaORM entity) and the gRPC handler mapping proto messages to/from the shared input types are local to this service. This is the concrete example of “extract only what’s actually identical, leave what’s genuinely per-service in the service.” payment-serviceis the only confirmed real caller today — wiring a card token/last4/brand intopci-serviceat the pointpayment-servicerecords a payment method, rather thanpayment-servicestoring card data itself.- Schema name
"pci-service"(not a sharedtenant/pcischema) follows the same per-microservice-schema conventionpii-servicealready set.
Related Documents
- pii-service — shares this service’s entire domain/service layer via
rust-lang-core-lib’s EAV pattern - payment-service — real caller, card-method storage
- ADR-00020 — Shared Core-Lib Encryption Pattern vs. In-Service Implementation
- ADR-00018 — Row-Based Encrypted Attribute Model and Address-Snapshot Exception
Full module reference: pci-service/CLAUDE.md.