How DynamoDB TTL Can Enhance Your Serverless Architecture
I had a humble beginning with Amazon DynamoDB. I heard that DynamoDB was the place to store the sessions in a serverless environment. So I created a table.
Many recommended the session identifier (ID) as the Partition Key (PK) and a timestamp attribute to store the creation time. I thought it was so simple.
Soon, the sessions were flourishing in millions. Adding a session, reading a session took just a few milliseconds. I was happy!
One day, I asked myself, how would I block someone from using an old session? Easy! Fetch the session, check the timestamp. If old, then delete it from the table. I couldn’t be happier!
A month passed. A smart engineer joined the team with full of questions.
“So, how do you remove old sessions?” she asked casually. With a sigh of relief, I explained the process — fetch the session, check the timestamp, etc.
With a suspicious look, she continued her next question. “What happens to those sessions that never get re-used?”.
Welcome to the world of TTL!
You only live twice in DynamoDB!!