Lambda polls shards in your DynamoDB stream for records at a base rate of 4 times per second. When records are available, Lambda invokes your function and waits for the result. If processing succeeds, Lambda resumes polling until it receives more records.
By default, Lambda invokes your function as soon as records are available in the stream. If the batch that Lambda reads from the stream only has one record in it, Lambda sends only one record to the function. To avoid invoking the function with a small number of records, you can tell the event source to buffer records for up to five minutes by configuring a batch window. Before invoking the function, Lambda continues to read records from the stream until it has gathered a full batch, or until the batch window expires.
DynamoDB Local and Global Secondary Indexes
Two types:
Local Secondary Indexes
Global Secondary Indexes
Things to know to understand this:
Query is the most efficientoperation in DDB.
Query can only work 1 PK value at a time.
Optionally a single, or range of SK values.
Indexes are alternative views on table data.
Different SK (LSI) or Different PK and SK (GSI).
You have the ability to choose some or all attributes (projection).
Local Secondary Indexes (LSI)
LSI is an alternative view for a table.
MUST be created with a table.
5 LSIs per base table.
Alternative SK on the table.
Shares the RCU and WCU with the table.
Attributes to project into the secondary index - ALL, KEYS_ONLY & INCLUDE.
Indexes are sparse, so only items which have the value in the index alternative sort key are added to the index. This can also help us for scan operations for capacity cost.
Global Secondary Indexes (GSI)
Can be created at any time.
Default limit of 20 per base table.
Alternative PK and SK.
GSIs have their own RCU and WCU allocations.
Attributes to project into the secondary index - ALL, KEYS_ONLY & INCLUDE.
GSIs are ALWAYS eventually consistent. Replication between base and GSI is asynchronous.
LSI and GSI Considerations
Careful with projection (KEYS_ONLY, INCLUDE, ALL).
Queries on attributes NOT projected are expensive.
Use GSIs as default, LSI only when strong consistency is required.
Use indexes for alternative access patterns.
DynamoDB Global Tables
Multi-master, cross-region replication.
Tables are creates in multiple regions and added to the same global table (becoming replica tables).
Last writer wins is used for conflict resolution.
Reads and Writes can occur to any region.
Generally sub-second replication between regions.
Strongly consistent reads ONLY in same region as writes.
Provides HA, Global RC/BC (Business continuity).
DynamoDB Accelerator (DAX)
An in-memory cache designed specifically for DynamoDB. It should be your default choic for any DynamoDB caching related questions.
DAX handles the cache check and missed requests.
Less complexity for app developer.
DAX is a cluster service where nodes are highly available.
There are two caches:
Item cache holds results of (Batch)GetItem.
The query cache holds data based on the query/scan parameters.
DAX is accessed via an endpoint. Cache HITS are returned in microseconds - misses in milleseconds.
DAX can use write-through caching for when writing to the database.
DAX Considerations
Primary Node (writes) and replicas (read).
Nodes are highly available. Primary failure = election.
In-Memory cache. Scaling - much faster reads, reduced costs.