Design a key management service
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Google's first round (coding), last asked Sep 2025. It tests security, cryptography and access control.
Design a key management service. A client presents a key id and gets the key material, or asks the service to encrypt, decrypt, sign or verify with that key. Specify the APIs, key generation and storage (hardware security modules versus software), access control, auditing, key rotation, usage limits, and the threat model. Discuss latency, availability, and the blast radius if something is compromised.
Requirements
- Functional: create symmetric and asymmetric keys per tenant; get key material where policy allows; encrypt, decrypt, sign and verify server-side; rotate keys while old ciphertext stays readable; disable, schedule deletion of, and restore keys; per-key policies and usage limits.
- Non-functional: very high availability (an outage stops every service that depends on it); low latency on the decrypt path; master keys never leave the HSM in plaintext; every use is audited; strict tenant isolation.
Clarifying questions
- Should clients ever receive raw key material, or only use keys through the service?
- How many tenants, keys and operations per second? Which operations dominate?
- What compliance requirements apply (for example FIPS 140 levels)?
- Is it single-region or global, and must keys stay inside a region?
- Who are the threats: outside attackers, compromised client services, insiders?
What a strong answer covers
- A key hierarchy: root keys inside HSMs, tenant or key-encryption keys wrapped by them, data keys wrapped by those (envelope encryption), so bulk data is encrypted locally and only small data keys hit the service.
- APIs:
CreateKey,GenerateDataKey,Encrypt,Decrypt,Sign,Verify,RotateKey,DisableKey,ScheduleKeyDeletion, with key versions so ciphertext carries the version it needs. - Storage: wrapped key material in a replicated database; HSM clusters per region; the trade-offs of HSMs (cost, throughput, latency) against software keys protected by an HSM-held root.
- Access control: per-key policies by caller identity and operation, short-lived credentials, separation of duties for administrators, and quorum approval for destructive actions.
- Audit: an append-only, tamper-evident log of every call with caller, key and result, streamed to the tenant.
- Rotation: new versions for new encryptions, old versions kept for decryption, re-encryption jobs when required.
- Availability and latency: regional active-active deployment, caching of unwrapped tenant keys in memory with short TTLs, rate limits per tenant, and graceful degradation.
- Blast radius: per-tenant and per-region keys, limits on how much data one key protects, and a compromise playbook (disable, rotate, re-encrypt).
Follow-ups
- A client service is compromised and is decrypting everything it can. How do you notice and stop it?
- A tenant wants to hold their own root key outside your service (bring or hold your own key).
- How do you delete a key safely when data encrypted with it may still exist?
Where it's asked
- Google · First round: coding · Last asked Sep 202545 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
What it tests
security · cryptography · access control
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
