Streams and polling are two ways to get updates from a database. Streams send changes as they happen, while polling checks for changes regularly.
You want to react immediately when data changes, like updating a live dashboard.
You need to process changes in order, such as syncing data between systems.
You want to reduce unnecessary checks to save resources and cost.
You have a simple app that can check for updates every few seconds without delay.
You want to keep your system simple and avoid managing stream processing.
Syntax
DynamoDB
Stream: Enable DynamoDB Streams on your table and use AWS Lambda or Kinesis to process changes.
Polling: Write code to query the table at intervals using Scan or Query operations.
Streams provide real-time change data capture.
Polling requires setting a time interval and may miss immediate changes.
Examples
This query fetches new or updated items since the last check.
DynamoDB
-- Polling example: Query table every 10 seconds
SELECT * FROM MyTable WHERE UpdatedAt > last_checked_time;
Lambda automatically runs when data changes, no need to query manually.
DynamoDB
// Stream example: Lambda function triggered by DynamoDB Stream
// Process each record as it arrives
Sample Program
This query fetches orders placed after June 1, 2024. You would run this repeatedly to check for new orders.
DynamoDB
-- Polling example: Get new items added after a timestamp
SELECT * FROM Orders WHERE OrderDate > '2024-06-01T00:00:00Z';
OutputSuccess
Important Notes
Streams are better for real-time and ordered processing.
Polling can cause delays and extra cost if done too frequently.
Use streams when you want to react instantly without writing polling code.
Summary
Streams push changes to you immediately.
Polling asks for changes at set times.
Choose streams for real-time needs, polling for simple or less time-sensitive tasks.
Practice
(1/5)
1. Which of the following best describes DynamoDB Streams compared to polling?
easy
A. Polling and streams both check for changes only once a day.
B. Polling pushes data changes immediately, streams check periodically.
C. Streams push data changes immediately, polling checks periodically.
D. Both streams and polling push data changes immediately.
Solution
Step 1: Understand DynamoDB Streams behavior
DynamoDB Streams send data change events as they happen, pushing updates immediately.
Step 2: Understand polling behavior
Polling requires the client to ask for updates at fixed intervals, not instantly.
Final Answer:
Streams push data changes immediately, polling checks periodically. -> Option C
Quick Check:
Streams = push, Polling = periodic check [OK]
Hint: Streams push instantly; polling waits for your request [OK]
Common Mistakes:
Confusing which method pushes data
Thinking polling is real-time
Assuming streams require manual checks
2. Which syntax correctly represents enabling DynamoDB Streams on a table using AWS CLI?
easy
A. aws dynamodb update-table --table-name MyTable --stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE
B. aws dynamodb enable-stream --table MyTable --type NEW_IMAGE
C. aws dynamodb create-stream --table-name MyTable --view NEW_IMAGE
D. aws dynamodb set-stream --table MyTable --enabled true
Solution
Step 1: Identify correct AWS CLI command for streams
The correct command to enable streams is 'update-table' with '--stream-specification' option.
Step 2: Verify syntax correctness
aws dynamodb update-table --table-name MyTable --stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE uses correct flags and parameters: StreamEnabled=true and StreamViewType=NEW_IMAGE.
Final Answer:
aws dynamodb update-table --table-name MyTable --stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE -> Option A
Quick Check:
Enable streams with update-table and stream-specification [OK]
Hint: Use update-table with --stream-specification to enable streams [OK]
Common Mistakes:
Using non-existent commands like create-stream
Incorrect flag names
Missing StreamEnabled parameter
3. Given a DynamoDB table with streams enabled, what will happen if you poll the table every 10 minutes instead of using streams?
medium
A. Polling disables streams temporarily.
B. You get real-time updates as soon as data changes.
C. Polling automatically triggers streams to push data.
D. You receive updates only every 10 minutes, possibly missing immediate changes.
Solution
Step 1: Understand polling frequency impact
Polling every 10 minutes means updates are checked only at those intervals, not instantly.
Step 2: Compare with streams behavior
Streams push changes immediately, so polling delays updates and may miss real-time events.
Final Answer:
You receive updates only every 10 minutes, possibly missing immediate changes. -> Option D