Minimal Schema Architecture for Certificate Storage
Docs for PKI Manager 3.17.0 (released 2026-11-24), from main 4d59c30 (30 commits after the release). Page last changed in 1.0.0.
Source:
backlog/decisions/decision-004 - Minimal-Schema-Architecture-for-Certificate-Storage.md
Context
Section titled “Context”The PKI Manager application needed to decide how to store certificate and CA data across two systems:
- Local SQLite database (for querying and application state)
- Cosmian KMS (for cryptographic key material and certificate storage)
Initial implementation stored complete certificate data in both locations, leading to:
- Data duplication between local DB and KMS
- Increased database size from large PEM-encoded certificates
- Maintenance burden of keeping both stores synchronized
- Unclear source of truth for certificate data
We needed an architecture that would:
- Eliminate data duplication
- Maintain fast query performance for lists and searches
- Establish clear single source of truth
- Minimize KMS API calls for acceptable performance
Decision
Section titled “Decision”We will implement a minimal schema approach with hybrid storage:
Local Database Stores:
Section titled “Local Database Stores:”-
KMS References (essential)
kms_certificate_id- Reference to fetch certificate from KMSkms_key_id- Reference to private/public keys
-
Query Optimization Fields (denormalized for performance)
subject_dn- For searching by subjectserial_number- For unique identificationnot_before,not_after- For expiry filtering
-
Application State (not in X.509 certificate)
status- active/revoked/expiredrevocation_date,revocation_reason- Workflow tracking
KMS Stores:
Section titled “KMS Stores:”- Complete certificate PEM data
- Private/public key material
- Certificate metadata
Removed from Local DB:
Section titled “Removed from Local DB:”- ❌
certificate_pem- Fetch from KMS on-demand - ❌
key_algorithm- Extract from certificate when needed
Fetch Strategy:
Section titled “Fetch Strategy:”- List operations: Use local DB metadata only (fast)
- Detail views: Fetch certificate from KMS on first access
- Export operations: Fetch from KMS when generating files
- No local caching of fetched PEM data
Implementation
Section titled “Implementation”Database Changes
Section titled “Database Changes”- Created migration
0002_minimal_schema.sql - Added
KMSService.getCertificate()method - Updated CA procedures to fetch on-demand
- Applied migration successfully
Files Modified
Section titled “Files Modified”backend/src/db/schema.ts- Minimal schema definitionbackend/src/kms/client.ts- Added getCertificate() KMIP operationbackend/src/kms/service.ts- Service wrapper with audit loggingbackend/src/trpc/procedures/ca.ts- On-demand fetching in getByIdbackend/src/db/migrations/0002_minimal_schema.sql- Schema migration
Test Results
Section titled “Test Results”- ✅ CA creation test passing
- ✅ 88 total tests passing
- Certificate procedures require similar updates (tracked in task-2)
Consequences
Section titled “Consequences”Positive
Section titled “Positive”- Single Source of Truth: KMS is authoritative for all certificate data
- Reduced Database Size: Large PEM strings eliminated from local storage
- No Data Synchronization: Certificate data can’t drift between systems
- Clean Architecture: Clear separation between query optimization and cryptographic storage
- Fast List Operations: Local metadata enables sub-millisecond queries
Negative
Section titled “Negative”- KMS Dependency: Certificate detail views require KMS availability
- Additional Network Calls: 1 KMS call per detail view/export operation
- Latency: ~50-100ms per KMS fetch (acceptable for detail views)
- Migration Complexity: Required recreating tables in SQLite
Neutral
Section titled “Neutral”- Implementation Effort: Certificate procedures need same pattern as CAs
- Frontend Impact: Minimal - already expects full data in detail views only
- Testing: Test expectations updated to match new response schema
Performance Impact
Section titled “Performance Impact”Measured:
- List operations: No change (uses local DB metadata)
- Detail views: +50-100ms for KMS fetch (acceptable)
- Export operations: +50-200ms depending on chain depth
Scalability:
- Local DB queries: O(log n) with indexes - excellent
- KMS fetches: O(1) per certificate - acceptable
- Memory: Reduced from ~5KB per cert (PEM) to ~500B (metadata)
Related Work
Section titled “Related Work”- Task task-2: Complete minimal schema migration for certificate procedures
- Migration:
backend/src/db/migrations/0002_minimal_schema.sql - KMS Documentation: Cosmian KMS KMIP specification
PKI Manager is a personal project of Oriol Rius, built for his own use. It is not a commercial product. About this project