Data Protection and Encryption in Practice Questions
Protecting data at rest and in transit across real systems from an engineering rather than pure-cryptography standpoint. Covers encryption strategy and key management for stored and transmitted data, secrets and sensitive-data handling, tokenization and secure elements for payment and sensitive data, and secure data handling in application code. Applied data-protection controls, distinct from cryptographic primitive design and from privacy-regulation compliance.
Propose a strategy for measuring and reporting the performance impact of encryption, CPU, memory, and network, across a heterogeneous fleet of VMs, containers, and serverless functions. How would you attribute observed latency to cryptographic operations rather than other causes?
Sample Answer
Direct answer
Measure the performance impact with a controlled, before/after or shadow-traffic comparison rather than reading raw fleet-wide averages, and attribute the delta specifically to cryptographic work using CPU profiling that names the actual cipher and handshake calls, not just an increase in end-to-end latency, since aggregate latency conflates cryptography with garbage collection, network queuing, and downstream service time.
Structured elaboration
Baseline comparison method: Where encryption can be safely toggled, for example TLS (Transport Layer Security) termination on versus off in a staging environment, or a canary with field-level encryption disabled versus enabled, hold every other variable constant and compare. Where production cannot safely disable encryption (usually the right call), replay synthetic or shadowed traffic against both configurations instead of touching production directly.
Fleet heterogeneity: VMs, containers, and serverless functions have very different baseline compute profiles and cold-start behavior, so a single blended average hides which platform is actually paying the cost. Measure cryptographic overhead as a relative delta per request or per operation, separately for each compute type, rather than one number across the whole fleet.
Attribution technique: Use CPU profiling (flame graphs) that can attribute time specifically to cryptographic library calls, for example time spent inside an AES-GCM encrypt call versus TLS handshake negotiation versus the rest of request handling, rather than inferring cryptographic cost purely from an aggregate latency increase. Check whether hardware crypto acceleration (AES-NI on the CPU, or a dedicated offload path) is actually enabled on each fleet, since the identical algorithm can look far more expensive on hardware that isn't using it, which is a configuration gap, not an inherent cost of encryption.
Serverless specifically: A cold start that has to call out to a KMS (Key Management Service) to unwrap a data key has a very different cost profile than a long-lived VM or container that keeps a decrypted key cached in memory. Report these separately; averaging them makes serverless look disproportionately "encryption-expensive" when the real cost is the KMS round trip on cold start, not the cipher itself.
Reporting: Report overhead as a relative delta against a clearly defined baseline and workload, not a bare absolute number, and break out CPU, memory, and network separately, since different mechanisms cost differently: TLS overhead is mostly CPU plus a small amount of network from handshake round trips, while a per-request KMS call is mostly network and external-service latency, not local CPU.
Worked example
One genuine, easily verified cost that doesn't require any benchmark at all is ciphertext expansion: AES-GCM (a standard authenticated encryption mode) adds a 12-byte nonce and a 16-byte authentication tag to every encrypted message, a fixed 28 bytes of overhead per message regardless of payload size. On a fleet moving small, frequent messages, that 28-byte expansion can itself explain part of an observed increase in network bytes transferred, independent of any CPU cost, and this is exactly the kind of decomposition a good attribution exercise should separate out: how much of the observed delta is genuinely cryptographic CPU work, how much is this fixed protocol overhead, and how much is an unrelated confound like a coincident garbage-collection change.
Trade-offs and pitfalls
The most common mistake is attributing an entire observed latency increase to "encryption" when a meaningful share is actually a downstream network hop or an unrelated change that happened to ship in the same release. The second most common is under-provisioning CPU: a hardware-accelerated cryptographic operation that looks nearly free on one instance type can become a real bottleneck once cores are saturated on another, making the same algorithm look expensive purely due to acceleration availability, not the algorithm itself.
Explain the practical differences between encryption at rest, encryption in transit, and encryption in use. For each category, give two concrete examples from a typical cloud and on-premise stack, and describe the primary threats each one defends against and the residual risk that remains even when it is correctly implemented.
Sample Answer
Direct answer
Data protection has to cover three different moments in a value's life: while it sits on a disk (at rest), while it moves across a network (in transit), and while a program is actively working with it in memory (in use). Each state has a different attacker in mind, and being strong in one gives you no protection in the others.
Structured elaboration
| State | What it protects | Typical mechanism | Defends against | Residual risk |
|---|---|---|---|---|
| At rest | Data stored on disk, in a database, or in an object store | Full-disk or volume encryption, database TDE (Transparent Data Encryption), object-store server-side encryption (SSE) | Theft of a physical drive, exfiltration of a raw backup or storage snapshot | An attacker with valid application credentials, or a bug that lets them query the app normally, still sees decrypted data |
| In transit | Data moving over a network | TLS (Transport Layer Security) between a browser and a server, mTLS (mutual TLS, where both sides present a certificate) between internal services | Eavesdropping or a man-in-the-middle on the network path | Nothing once the data lands: whatever sits unencrypted on either endpoint before send or after receive is fully exposed |
| In use | Data actively being processed by the CPU | Confidential computing: hardware-isolated memory regions (Trusted Execution Environments) that keep even the host operating system or hypervisor from reading process memory | A compromised host OS, hypervisor, or cloud operator trying to read a running process's memory | A bug in the code running inside the protected region, or a side-channel attack against the hardware itself, both bypass it |
The same logic scales across an enterprise's whole storage surface, not just one database: a relational database's TDE, an object store's SSE, a message queue's on-disk encryption (for example Kafka's disk-level encryption), and encrypted backups are all just different instances of "at rest," judged by the same threat model. Who actually holds the key matters as much as whether encryption exists at all: a secrets manager might use a fully provider-managed key inside a cloud KMS (Key Management Service, the service that generates and guards encryption keys), or you might bring your own key (BYOK), which changes whether the provider itself could ever access your data even under compulsion.
Worked example
A payment record moves through three states in one request: it is written to a database with TDE enabled (at rest), read back by an API service over mTLS (in transit), then held in that service's memory while an interest calculation runs (in use). If the at-rest and in-transit controls are both configured correctly, a SQL injection vulnerability in the application layer can still read the row in plaintext, because the app is trusted to decrypt it as part of normal operation. Encryption at rest defends against someone bypassing the app to read raw storage, not against someone abusing the app itself.
Trade-offs and pitfalls
Encryption at rest and in transit are inexpensive, mature, and should be the default everywhere. Encryption in use is a much heavier tool: it requires specialized hardware, has real performance and compatibility costs, and should be reserved for cases where you specifically distrust the infrastructure operator (your own cloud provider, or a shared host) rather than applied by default. None of the three states protect against an authorization bug, an insider with legitimate key access, or a compromised credential; they are complementary controls, not substitutes for access control.
Design encrypted backups for a production database such that the backups remain confidential, are recoverable even after a key-loss event, and support point-in-time restore across regions. Cover where key material is stored relative to the backup, what backup metadata you need, and how you would test that a restore actually works.
Sample Answer
Direct answer
Wrap each backup's data key with a key held in a KMS (Key Management Service) or HSM (Hardware Security Module), but the design constraint that actually matters is keeping a break-glass path to that wrapping key that survives a failure independent of your normal operations, otherwise "encrypted backup" quietly becomes "permanently destroyed backup" the moment the primary key becomes unavailable.
Structured elaboration
Where key material lives relative to the backup: Never store the unwrapped data key, or the wrapping key itself, alongside the backup data; an attacker or ransomware actor who gets both at once gets a fully usable copy. Keep KMS- or HSM-held keys in a separate account, region, or trust boundary from backup storage, and maintain a genuine disaster-recovery path for the wrapping key itself, for example a multi-region replica key in a cloud KMS, or a documented, sealed physical key-recovery procedure, for scenarios where the primary key management system is itself unavailable or deleted.
Backup metadata needed: Record which key ID and key version wrapped this specific backup, since keys rotate over a backup's retention period and an old backup can only be restored with the historical key version that actually protected it. Also record a timestamp, source region, and a checksum of the plaintext for restore verification, plus enough catalog information to locate the correct backup for a point-in-time restore into a target region without decrypting every candidate just to check.
Cross-region point-in-time restore: Replicate the encrypted backup (still ciphertext) to the target region, and separately ensure the wrapping key is usable there too, for example through a multi-region KMS key. Shipping ciphertext without shipping (or re-wrapping for) the corresponding key access leaves an unreadable backup in the new region.
Testing that restores actually work: Schedule regular, automated restore drills that decrypt a real backup and validate it at the application level, row counts, checksums, a smoke-test query, rather than trusting a "backup completed" status, which only proves bytes were written and encrypted, not that they can be read back. Specifically test the disaster path, restoring via the break-glass key procedure, not only the everyday path, since the break-glass path is the one most likely to have quietly rotted from disuse.
Worked example
A nightly database snapshot is encrypted with a data key, which is itself wrapped by KMS key K1 at its current version, version 3. The backup object is stored with metadata {key_id: K1, key_version: 3, checksum, timestamp}, and replicated to a second region where K1 exists as a multi-region replica key. Because K1 rotates quarterly, a monthly restore drill deliberately pulls a backup from six months earlier, wrapped under K1 version 1, and confirms that version is still resolvable and the restore completes end to end, not just the most recent backup under the current key version.
Trade-offs and pitfalls
A very common failure mode is a KMS key deletion, most cloud providers enforce a mandatory waiting period before a scheduled key deletion completes specifically as a safety net, triggered by unrelated cleanup automation that silently orphans every backup wrapped by that key. Treat key deletion as a rare, high-blast-radius, deliberately friction-heavy operation, and track which backups depend on a given key so one is never deleted while backups still reference it.
Describe the TLS handshake at a high level and explain how it protects data in transit. As someone reviewing a web server's configuration, which specific checks would you perform: cipher suites, supported protocol versions, certificate validation, and renegotiation behavior?
Sample Answer
Direct answer: TLS (Transport Layer Security, the protocol that encrypts and authenticates traffic between a client and a server) protects data in transit by having the client and server agree on a shared secret key over a public network without ever sending that key in the clear, then encrypting everything that follows with it. Reviewing a server's configuration means checking four things: which cipher suites (the specific combination of algorithms used for key exchange, encryption, and integrity checking) are enabled, which protocol versions are allowed, whether certificate validation is strict, and whether renegotiation is handled safely.
Structured elaboration:
The handshake, at a high level. First, the client sends a ClientHello proposing a TLS version and a list of cipher suites it supports. The server replies with a ServerHello picking a cipher suite from that list, plus its certificate, which proves its identity by being signed by a certificate authority the client already trusts. Both sides then derive a shared symmetric session key through a key exchange, most modern TLS uses a Diffie-Hellman-based exchange, which lets both sides compute the same secret from public values even though an eavesdropper sees those same public values. Finally, both sides confirm the handshake wasn't tampered with, and every message after that point is encrypted with the shared session key. TLS 1.3 compresses this into fewer round trips than TLS 1.2, but the underlying shape, agree on parameters, exchange keys, confirm, then encrypt, is the same.
What to check when reviewing a server's configuration. Cipher suites: disable legacy or weak suites, anything using RC4, 3DES, or export-grade cryptography, or that lacks forward secrecy (a property where each session uses a fresh key, so stealing the server's long-term key later cannot decrypt past recorded traffic), and prefer AEAD (authenticated encryption with associated data, a cipher mode that encrypts and checks integrity in one step) ciphers such as AES-GCM. Protocol versions: disable SSLv3, TLS 1.0, and TLS 1.1; require TLS 1.2 as a floor and prefer TLS 1.3 wherever every supported client can use it. Certificate validation: confirm the certificate chains to a trusted root, hasn't expired, and its subject or SAN (Subject Alternative Name, the field listing which hostnames a certificate is valid for) actually matches the hostname being served, and confirm revocation checking via OCSP or a certificate revocation list is configured, since an expired-but-unchecked certificate is a common gap. Renegotiation: TLS renegotiation is a client or server re-running the handshake on an already-open connection to refresh keys or parameters; disable client-initiated renegotiation, or at minimum ensure secure renegotiation is enforced, since insecure renegotiation was the root of a well-known man-in-the-middle class of attack against older TLS deployments.
Certificate validation in practice means checking the whole trust chain, not just the leaf certificate: the chain runs from the server's own certificate up through one or more intermediate certificate authorities to a root the client already trusts, and a server that omits an intermediate certificate will fail validation for clients that don't already cache it, even though the leaf certificate itself is fine. Mutual TLS, or mTLS, where both sides present a certificate rather than just the server, is called for when you need cryptographic proof of the client's identity too, which is the normal case for service-to-service traffic inside a zero-trust network, or for a business-to-business API where you want to authenticate the calling organization by certificate rather than, or in addition to, an API key.
Worked example: A server offering TLS 1.0 alongside TLS 1.3, with a cipher list that still includes a 3DES suite, and no OCSP stapling configured, fails this review on three of the four checks: drop TLS 1.0 and the 3DES suite, and add OCSP stapling, where the server proactively attaches revocation-status proof to its own handshake instead of making every client query the certificate authority separately.
Trade-offs and pitfalls: Disabling old protocol versions and weak ciphers can break traffic from clients that genuinely can't be upgraded, some older devices only speak TLS 1.0. That's usually still the right trade to make, but it needs to be a deliberate, communicated decision rather than a surprise outage.
A developer just committed a file containing a plaintext API key to the main repository. Walk through your immediate containment steps, then list at least five long-term controls, both preventive and detective, you would put in place to reduce the risk of this happening again.
Sample Answer
Direct answer
Deleting the file and recommitting does not solve the problem: git history retains every prior commit, so the key is still recoverable by anyone who can clone the repository or has already pulled it. Treat the key as compromised the moment it was pushed to a shared remote, revoke or rotate it immediately at the provider, then work through containment and longer-term controls in that order.
Structured elaboration
Immediate containment steps:
- Revoke or rotate the exposed key at the provider right away, before touching git history. This is the step that actually neutralizes the exposure; rewriting history alone does not, because the key value itself remains valid until revoked.
- Check the provider's usage/audit logs for the key covering the exposure window, to see whether anyone already made unauthorized calls with it.
- Purge the value from git history (for example with
git filter-repoor the BFG Repo-Cleaner) if the old committed value matters for other reasons, understanding this rewrites history and requires a force-push and coordination with every collaborator who has a local clone. - Notify the teams or stakeholders whose systems the key had access to, especially if it had broad scope.
Long-term controls (preventive):
- Pre-commit secret-scanning hooks (for example gitleaks, git-secrets, detect-secrets) that catch a secret before the commit is even created.
- Server-side push protection (GitHub secret scanning push protection or the GitLab equivalent) that blocks the push outright rather than relying on every developer's local hook being installed.
- Short-lived, dynamically issued credentials wherever feasible, so a value that does leak is only useful for minutes rather than indefinitely.
- Least-privilege scoping on every issued credential, so a leak's blast radius is small even when it happens.
- A documented "if you leak a secret" runbook and developer training, so the first instinct is rotate-and-report, not delete-and-recommit.
Long-term controls (detective):
6. Continuous, scheduled full-history repository scanning, catching anything that slipped past commit-time and push-time checks.
7. Provider-side anomaly and usage alerting on the credential itself (unexpected source IPs, unusual call volume).
8. Centralized secrets-manager or credential audit logs correlated into a SIEM (Security Information and Event Management system), so unusual access patterns surface without anyone manually checking logs.
Worked example
A developer commits a .env file containing a live third-party API key and pushes to the shared remote. Within the hour: the key is revoked at the provider and a new one is issued through the team's secrets manager; the provider's usage logs are checked and show no unauthorized calls during the exposure window; the repository history is rewritten with git filter-repo since the same value should never resurface even accidentally, and every collaborator is asked to re-clone rather than merge their stale local history.
Trade-offs and pitfalls
Rewriting shared git history is disruptive (every collaborator must re-clone or rebase), so it is worth doing only when the actual value matters beyond the fact that it once existed; if the key has already been rotated, the primary remaining reason to scrub history is hygiene and audit clarity, not active risk reduction, since the compromised value is no longer valid regardless of whether it's still visible in an old commit.
Unlock Full Question Bank
Get access to all 12 Data Protection and Encryption in Practice interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.