SecurityPerformanceArchitecture

High-Performance Application-Level Encryption: Sub-Millisecond Access Control

Build ultra-fast encrypted systems that keep data secure from DB admins while delivering sub-millisecond performance through intelligent caching and role-based access control.

SyntheBrain Team
August 29, 2025
25 min read

Application-Level Encryption

Zero-Trust Security + Sub-Millisecond Performance

The Challenge: Security vs Performance

The Traditional Dilemma

Most encryption solutions force you to choose: either accept database administrators can read your sensitive data, or sacrifice performance with round-trips to key management services on every database read.

In today's zero-trust security landscape, application-level encryption has become essential. Your database administrators, cloud providers, and even your own infrastructure team shouldn't have access to sensitive plaintext data. But traditional approaches often introduce significant latency penalties.

What We'll Build

  • App-level encryption - DB admins can't read plaintext
  • Role-based access - Decryption gated by caller's token/policy
  • Sub-millisecond hot-path - No KMS round-trips after first access
  • Enterprise-ready - Key rotation, audit trails, multi-tenancy

High-Level Architecture

Our solution uses a five-component architecture that implements envelope encryption with policy-based access control, intelligent caching, and zero-plaintext storage.

Components

1. Identity (Auth0/IdP)

Issues JWT with roles/claims for authentication and authorization.

2. PDP (Policy Decision Point)

OPA/Cedar checks JWT claims against "who may use which keys for which purpose".

3. Crypto Service

Internal microservice using Vault/KMS as KEK authority. Implements envelope encryption + data-key cache with AEAD primitives.

4. Data Service(s)

Business read/write APIs. Never touch raw keys; only call Crypto Service.

5. Database

Stores ciphertext + metadata (no plaintext).

Zero-Trust Encryption Pipeline

End-to-end security with sub-millisecond performance

Identity Layer (Auth0/IdP)

JWT Token with Claims

sub
user-123
roles
admin
tenant
org_123
scope
read:data

Policy Decision Point (OPA/Cedar)

Policy Evaluation Engine

if (jwt.role == "admin" &&
jwt.tenant == record.tenant)
then ALLOW
else DENY

Crypto Service (High-Performance Core)

AEAD Primitives + Intelligent Caching

Cache Manager
  • • LRU + TTL
  • • Sub-ms lookup
  • • Bounded size
AEAD Crypto
  • • AES-GCM
  • • ChaCha20
  • • Poly1305
KMS Client
  • • Vault
  • • Azure KV
  • • AWS KMS
encrypt(payload, context)
decrypt(ciphertext, ctx)

Data Services (Business Logic)

Never touch raw keys

User API
Profile management
Order API
Transaction processing
Payment API
Secure payments

Encrypted Database (Zero Plaintext)

Envelope Encryption Record Structure

🆔 record_id
uuid-4567-89ab-cdef
🏢 tenant_id
org_12345
🔒 ciphertext
[AES-GCM encrypted]
📝 aad_context
org_12345|payment|pci
🔐 dek_encrypted
[KEK-wrapped DEK]
🏷️ kek_id
vault://payment-keys/v2
📊 version
crypto_v1.2
🔍 blind_indexes
[HMAC search tags]

Envelope Encryption Layout (per record)

Database Record Structure

Each encrypted record contains these fields for complete envelope encryption with searchability and key rotation support.

record_id

Unique record identifier

uuid-4567-89ab-cdef
tenant_id

Multi-tenant isolation

org_12345
ciphertext

AES-GCM (or ChaCha20-Poly1305)

[Encrypted payload bytes]
aad_context

Additional authenticated data (not secret)

tenant_id|record_id|purpose
dek_encrypted

DEK wrapped with tenant/purpose KEK

[KEK-wrapped data encryption key]
kek_id

Which KEK wrapped the DEK (for rotation)

vault://payment-keys/v2
version

Crypto params versioning

crypto_v1.2
blind_indexes[]optional

For search: HMAC/FPF/Deterministic tags

[Searchable encryption indexes]
Identity
Record & tenant IDs
Encryption
Ciphertext & context
Key Management
DEK & KEK references
Metadata
Version & search indexes

Core Flows

1) Write/Update (Encrypt)

1

Authentication & Authorization

Data Service authenticates caller (JWT) → sends JWT + purpose/tenant to PDP for policy check.

2

Policy Decision

PDP returns "allowed" → Data Service calls Crypto Service: encrypt(payload, context)

3

Crypto Service Processing

  • Fetch DEK for (tenant, purpose) from in-memory cache
  • On cache miss: Generate fresh DEK, wrap with KEK in Vault/KMS
  • Cache plaintext DEK with short TTL (5-15 minutes) and LRU eviction
  • AEAD encrypt with AES-GCM, using context as AAD (binds to tenant/id)
4

Database Storage

Store complete envelope encryption record:

ciphertextdek_encryptedkek_idversionaad_contextblind_indexes

2) Read (Decrypt)

1

Authentication & Policy Check

Data Service authenticates caller (JWT) → PDP checks role/policy for decrypt on (tenant, purpose).

2

Authorized Decryption Request

If allowed, Data Service calls Crypto Service with:

dek_encryptedkek_idciphertextaad_context
3

Crypto Service Processing

  • Cache lookup: DEK via cache key = hash(dek_encrypted)
  • On cache miss: Unwrap with KMS/Vault (one network call)
  • Cache DEK with TTL for future requests
  • AEAD decrypt and return plaintext to Data Service

Latency Characteristics

First Access (Cold Path)
10-50ms

After TTL expiry, pays 1 KMS/Key Vault call (typical cloud latency)

Hot Path (Cached)
~µs

AEAD in memory only, zero remote calls - sub-millisecond performance

Performance Impact

Cache hit ratio of 95%+ means most operations run at memory speed with zero external dependencies.

Policies & Key Management Strategy

Policies & Key Scoping

KEK names and aliases reflect authorization scope, enabling fine-grained access control across tenants and data purposes.

KEK Naming Convention

kek/tenantA/payments
Payment processing scope
kek/tenantA/pii
Personal data scope
kek/global/audit
Cross-tenant audit logs

PDP Rule Example

"Role PAYMENTS_READER can use decrypt with kek/tenantA/payments for purpose=payments.read."

The Crypto Service enforces PDP decision before any unwrap/decrypt call; Vault/KMS also enforces at the API level via caller/service principal IAM.

Search & Querying Options

Strategic approaches for enabling search on encrypted data while maintaining security.

Non-Sensitive Columns

Don't encrypt columns you must filter/sort on. Keep timestamps, status fields, and public IDs in plaintext.

Equality Search

Blind Index
HMAC(pepper, normalize(value)) in separate column
Deterministic AEAD
AES-SIV for equality-only (⚠️ leaks equality)

Prefix/Range Search

Requires specialized constructs (FPF/OPRF or external searchable index). Only implement if truly needed; document leakage trade-offs carefully.

Key Rotation & Re-wrapping

KEK Rotation (Fast)

Re-wrap stored dek_encrypted from kek_v1 → kek_v2 without touching ciphertext.

Batch job through Crypto Service

DEK Rotation (Heavier)

Re-encrypt payload with new DEK. Only for strict compliance regimes or annual policy.

Full re-encryption required

Multi-tenant Strategy

Isolation Strategy

Per-tenant KEKs

Keep blast radius small and policies straightforward

Per-record DEKs

Maximum isolation; cache keeps it fast

Session DEKs

HKDF-derived for chatty workloads; short TTL

Performance Tactics (What Actually Keeps It Fast)

Performance Characteristics

< 1ms
Hot Path (cache hit)
~50ms
Cold Path (KMS trip)
10k+
Ops/sec per service
Zero
Plaintext in DB

Data-Key Cache in Crypto Service

Cache Configuration

Bounded Size + TTL
5-15 min TTL, LRU eviction
Cache Key
hash(dek_encrypted) + kek_id
Security
Zeroize on eviction

Performance Optimizations

Connection Pooling
To Vault/KMS with backoff
Circuit Breaker
Exponential backoff
Batch Unwrap
Burst read optimization

AEAD Implementation

Supported Algorithms
AES-GCMChaCha20-Poly1305
AAD Context
tenant_id|record_id|purpose

Auditing & Observability

Audit Logging

Log every unwrap/decrypt attempt with comprehensive context (no secrets logged).

Request ID:req_abc123
Subject:user@tenant.com
Purpose:payments.read
Decision:ALLOW

Metrics & Monitoring

Comprehensive performance and health metrics for operational visibility.

KMS Metrics
Call count/latency tracking
Cache Performance
Hit-rate monitoring
Error Tracking
Decrypt error rate
Key Rotation
Progress monitoring

Failure Modes & Fallbacks

Vault/KMS Unavailable

Hot Path Continues

Operations continue as long as DEKs are in cache. Existing encrypted data remains accessible.

New Keys Fail Closed

New/missed keys return 503 with retriable error code. System degrades gracefully.

Policy Decision Point Unavailable

Default Deny

Fail secure by default. All policy decisions return DENY when PDP is unreachable.

Optional: Last-Known TTL

For SLO requirements: use last-known decision with very short TTL. Document risk carefully.

Key Cache Poison Protection

Protect against cache poisoning attacks through cryptographic binding and integrity verification.

Cache Binding
cache_key = hash(dek_encrypted + kek_id)
Integrity Check
Verify unwrap integrity on every use

Performance Targets

< 1ms
Hot-path decryption after cache warm-up
Zero
KMS calls on cached operations
100%
Data protected from DB admin access

Implementation Sketch (Spring Boot)

Crypto Service Module

Service Ports

EncryptPort
encrypt(byte[] payload, Context ctx) -> CipherRecord
DecryptPort
decrypt(CipherRecord rec, Context ctx) -> byte[]

Technology Stack

Cryptography

Google Tink (AEAD/DeterministicAead)

Key Management

Azure Key Vault / AWS KMS / Vault Transit

Policy Engine

OPA sidecar or embedded Cedar

Decryption Flow Implementation

// Retrieve encrypted record from database
CipherRecord rec = repository.find(id);

// Policy check - throws exception if not allowed
policy.check(jwt, "decrypt", rec.kekId, rec.purpose);

// Get AEAD instance from cache (with automatic unwrap on miss)
Aead aead = dekCache.get(rec.dekEncrypted, rec.kekId, () -> {
    byte[] dek = kms.unwrap(rec.dekEncrypted, rec.kekId);   // one remote call on miss
    return AeadFactory.fromRawKey(dek);                     // build AEAD (keep in cache)
});

// Decrypt and return plaintext
byte[] plaintext = aead.decrypt(rec.ciphertext, rec.aadContext);
Key Performance Features
  • Cache-first approach: DEK lookup from in-memory cache
  • Lazy KMS calls: Only unwrap on cache miss
  • Policy enforcement: Every decrypt operation is authorized
  • AAD binding: Ciphertext cryptographically bound to context

When to Consider Alternatives

DB Transparent Encryption (TDE / Column Encryption)

Good For

  • • Disk theft protection
  • • Basic compliance requirements
  • • Infrastructure-level encryption

Not Sufficient For

  • • App-layer access control
  • • DBA threat protection
  • • Fine-grained policies

Tokenization / Vault Detokenization

Great for: PAN/SSN fields with strict compliance & format needs. Usually complements, not replaces, envelope encryption.

PCI DSSFormat PreservingCompliance

Proxy Re-Encryption (PRE)

Powerful for: Cross-org sharing without re-encrypting, but heavier ops/crypto. Use only if you truly need third-party re-sharing workflows.

⚠️ Consider complexity vs. benefit trade-offs

Confidential Computing (TEE/Nitro/SGX)

Raises bar on: In-memory key exposure protection. Consider for high-sensitivity tiers requiring hardware-level security.

Ship-it Checklist

1

Define purposes and kek_id taxonomy

Establish clear naming conventions for KEKs and data purposes

2

Author PDP policies; add unit tests for allow/deny

Implement comprehensive policy rules with test coverage

3

Stand up Crypto Service with AEAD + DEK cache and Vault/KMS integration

Deploy core encryption service with caching and key management

4

Add blind indexes only where needed; document leakage

Implement searchable encryption with clear security trade-offs

5

Wire audit logs + metrics; SLOs and alerts for KMS latency, cache hit-rate

Comprehensive observability and performance monitoring

6

Build KEK re-wrap and DEK rotate jobs

Automated key rotation and lifecycle management

7

Pen-test: nonce reuse guards, AAD binding, key-material zeroization

Security validation and cryptographic implementation testing

Bottom Line

Use envelope encryption with a short-lived data-key cache behind a policy-enforcing Crypto Service. It keeps your hot-path fast, binds decryption to roles/policies, and gives you clean rotation and auditing.

For Equality Search

Add blind indexes with documented trade-offs

For Stricter Isolation

Layer tokenization where appropriate

For Cross-Org Sharing

Consider PRE for re-sharing workflows