Bird
Raised Fist0
DynamoDBquery~20 mins

TTL use cases (sessions, logs, cache) in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
TTL Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
TTL impact on session data expiration

You have a DynamoDB table storing user sessions with a TTL attribute set to expire sessions after 30 minutes. Which of the following describes the expected behavior of expired session items?

AExpired session items are archived automatically to another table before deletion.
BExpired session items remain in the table indefinitely until manually deleted.
CExpired session items are deleted eventually but not immediately after TTL time passes.
DExpired session items are immediately deleted from the table as soon as TTL time passes.
Attempts:
2 left
💡 Hint

Think about how DynamoDB handles TTL deletions asynchronously.

🧠 Conceptual
intermediate
2:00remaining
Choosing TTL for log data retention

You want to store application logs in DynamoDB and automatically remove logs older than 7 days. What is the best way to implement this using TTL?

ASet a TTL attribute on each log item with a timestamp 7 days after the log creation time.
BSet TTL attribute to the current time to delete logs immediately.
CUse a global secondary index to filter logs older than 7 days and delete them manually.
DManually scan and delete logs older than 7 days every hour.
Attempts:
2 left
💡 Hint

TTL works by specifying an expiration timestamp on each item.

📝 Syntax
advanced
2:00remaining
Correct TTL attribute format for cache expiration

Which of the following DynamoDB item attributes correctly sets TTL for cache expiration?

{
  "CacheKey": "item123",
  "Data": "some cached data",
  "ExpiresAt": ?
}
AExpiresAt: 1717262400
BExpiresAt: "12:00:00"
CExpiresAt: "2024-06-01T12:00:00Z"
DExpiresAt: true
Attempts:
2 left
💡 Hint

TTL attribute must be a Unix epoch time in seconds.

❓ optimization
advanced
2:00remaining
Optimizing TTL usage for high write volume logs

You have a high volume of log entries written to DynamoDB with TTL set to 30 days. What is the best practice to optimize table performance and cost?

AUse a single large table with TTL enabled and no partition key changes.
BCreate multiple tables partitioned by month and enable TTL on each to reduce item scans.
CDisable TTL and manually delete old logs using batch operations.
DSet TTL to a very short time like 1 hour to reduce storage costs.
Attempts:
2 left
💡 Hint

Think about how partitioning affects performance and TTL cleanup.

🔧 Debug
expert
2:00remaining
Why are expired cache items not deleted as expected?

You set TTL on cache items with an attribute named "expiryTime" as Unix epoch seconds. After several days, expired items still appear in the table. What is the most likely cause?

ATTL attribute value is a string instead of a number.
BDynamoDB TTL deletes items only once per day, so delay is expected.
CTTL attribute value is set to a future timestamp instead of past.
DTTL attribute name in DynamoDB TTL settings does not match "expiryTime" exactly.
Attempts:
2 left
💡 Hint

Check the TTL attribute name configured in the table settings.

Practice

(1/5)
1. What is the main purpose of TTL (Time To Live) in DynamoDB?
easy
A. Automatically delete items after a specified time to save storage
B. Encrypt data for security
C. Backup data to another region
D. Increase read capacity automatically

Solution

  1. Step 1: Understand TTL functionality

    TTL marks items with an expiration timestamp to delete them automatically after that time.
  2. Step 2: Identify the main benefit

    This automatic deletion helps save storage and keeps data fresh without manual cleanup.
  3. Final Answer:

    Automatically delete items after a specified time to save storage -> Option A
  4. Quick Check:

    TTL = automatic deletion [OK]
Hint: TTL deletes expired data automatically to save space [OK]
Common Mistakes:
  • Confusing TTL with encryption
  • Thinking TTL backs up data
  • Assuming TTL changes capacity settings
2. Which attribute type must the TTL attribute have in a DynamoDB table?
easy
A. String representing a date
B. Boolean indicating expiration
C. Binary data
D. Number representing epoch time in seconds

Solution

  1. Step 1: Check TTL attribute requirements

    DynamoDB TTL requires a Number attribute that stores the expiration time as epoch time in seconds.
  2. Step 2: Eliminate other types

    String, Boolean, or Binary types are not valid for TTL expiration timestamps.
  3. Final Answer:

    Number representing epoch time in seconds -> Option D
  4. Quick Check:

    TTL attribute = epoch seconds number [OK]
Hint: TTL attribute must be a number with epoch seconds [OK]
Common Mistakes:
  • Using string dates instead of numbers
  • Setting TTL attribute as Boolean
  • Using binary data for TTL
3. Given a DynamoDB table with TTL enabled on attribute expireAt, what happens to an item with expireAt set to a timestamp 10 minutes in the past?
medium
A. The item is automatically deleted by DynamoDB
B. The item remains until manually deleted
C. The item is archived automatically
D. The item is updated with a new timestamp

Solution

  1. Step 1: Understand TTL expiration behavior

    Items with TTL timestamps in the past are marked for deletion by DynamoDB automatically.
  2. Step 2: Confirm deletion timing

    DynamoDB deletes expired items typically within 48 hours after expiration, often sooner.
  3. Final Answer:

    The item is automatically deleted by DynamoDB -> Option A
  4. Quick Check:

    Expired TTL item = auto delete [OK]
Hint: Expired TTL items get deleted automatically [OK]
Common Mistakes:
  • Thinking expired items stay forever
  • Assuming items get archived
  • Believing TTL updates timestamps automatically
4. You enabled TTL on attribute sessionExpiry but items are not being deleted after expiration. What is the most likely cause?
medium
A. TTL only works on string attributes
B. The table has no primary key defined
C. The sessionExpiry attribute is missing or not a number
D. DynamoDB does not support TTL

Solution

  1. Step 1: Check TTL attribute correctness

    TTL requires the attribute to exist and be a number representing epoch time; missing or wrong type prevents deletion.
  2. Step 2: Verify other options

    Tables must have primary keys, but that doesn't affect TTL. TTL does not work on strings. DynamoDB supports TTL.
  3. Final Answer:

    The sessionExpiry attribute is missing or not a number -> Option C
  4. Quick Check:

    TTL attribute missing or wrong type = no deletion [OK]
Hint: TTL attribute must exist and be a number [OK]
Common Mistakes:
  • Assuming TTL works on strings
  • Ignoring missing TTL attribute
  • Thinking DynamoDB lacks TTL support
5. You want to use TTL to automatically expire cached items after 1 hour. Which approach correctly sets the TTL attribute cacheExpire when inserting an item?
hard
A. Set cacheExpire to current date string plus 1 hour
B. Set cacheExpire to current epoch time plus 3600 seconds
C. Set cacheExpire to Boolean true
D. Do not set cacheExpire attribute

Solution

  1. Step 1: Calculate TTL expiration timestamp

    TTL requires a number representing epoch time in seconds, so add 3600 seconds (1 hour) to current epoch time.
  2. Step 2: Confirm correct attribute setting

    Setting a string or Boolean won't work; omitting the attribute disables TTL for that item.
  3. Final Answer:

    Set cacheExpire to current epoch time plus 3600 seconds -> Option B
  4. Quick Check:

    TTL = current time + seconds [OK]
Hint: TTL value = current epoch seconds + expiration seconds [OK]
Common Mistakes:
  • Using date strings instead of epoch seconds
  • Setting TTL as Boolean
  • Not setting TTL attribute at all
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard