Encryption at rest in Kafka - Time & Space Complexity
When Kafka encrypts data stored on disk, it adds extra steps to protect information.
We want to know how the time to write or read data changes as the data size grows.
Analyze the time complexity of the following Kafka encryption process.
// Simplified Kafka encryption at rest
byte[] data = fetchData();
byte[] encryptedData = encrypt(data, key);
writeToDisk(encryptedData);
This code fetches data, encrypts it, and writes the encrypted data to disk.
Look for repeated work that depends on data size.
- Primary operation: Encrypting each byte of data.
- How many times: Once for every byte in the data.
As data size grows, encryption work grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 bytes | About 10 encryption steps |
| 100 bytes | About 100 encryption steps |
| 1000 bytes | About 1000 encryption steps |
Pattern observation: The work grows directly with the amount of data.
Time Complexity: O(n)
This means the time to encrypt data grows in a straight line with data size.
[X] Wrong: "Encryption time stays the same no matter how much data there is."
[OK] Correct: Encryption must process every byte, so more data means more work.
Understanding how encryption time grows helps you explain system speed and design choices clearly.
"What if Kafka used chunked encryption that processes fixed-size blocks regardless of total data size? How would the time complexity change?"