Encryption at rest and in transit in DynamoDB - Time & Space Complexity
We want to understand how the time needed to encrypt and decrypt data changes as the amount of data grows in DynamoDB.
How does encryption affect the speed when storing or retrieving data?
Analyze the time complexity of encrypting and decrypting data in DynamoDB.
// Example pseudocode for encryption at rest and in transit
PutItem({
TableName: "MyTable",
Item: encryptData(userData), // encrypt before storing
});
GetItem({
TableName: "MyTable",
Key: userKey,
}).then(data => decryptData(data.Item)); // decrypt after retrieving
This code encrypts data before saving it and decrypts data after reading it from DynamoDB.
Look at what happens repeatedly when encrypting or decrypting data.
- Primary operation: Encrypting or decrypting each piece of data.
- How many times: Once per item stored or retrieved.
As the size of the data grows, the time to encrypt or decrypt grows roughly in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 KB | 10 units of encryption/decryption work |
| 100 KB | 100 units of encryption/decryption work |
| 1000 KB | 1000 units of encryption/decryption work |
Pattern observation: The work grows linearly as data size increases.
Time Complexity: O(n)
This means the time to encrypt or decrypt data grows directly with the size of the data.
[X] Wrong: "Encryption time stays the same no matter how big the data is."
[OK] Correct: Encryption processes each byte, so bigger data takes more time.
Understanding how encryption time grows helps you explain performance impacts clearly and shows you know how security affects database operations.
"What if we switched to encrypting only parts of the data instead of the whole item? How would the time complexity change?"