DynamoDB in Real Life Jonathon Hill - Upstate PHP

@compwright compwright.com

For every advantage there is an equal and opposite disadvantage.

Cost-efficient Unlimited scaling Stateless Transactions Parallel operations

Atomic counters Conditional writes Expiration Encryption Streaming

No indexes* No date support Small records Slow console Bad design = $$$

Idiosyncrasies

Query Scan GetItem PutItem UpdateItem DeleteItem TransactGetItems TransactWriteItems BatchGetItem BatchWriteItem …and more

500 InternalServerError 400 ProvisionedThroughputExceededException 400 RequestLimitExceeded 400 ResourceNotFoundException

NULL: null BOOL: boolean S: string N: number B: binary SS: string set NS: number set BS: binary set L: list M: map

Eventually Consistent Strongly Consistent Transactional Read per 4k 1/2 RCU 1 RCU 2 RCU Write per 1k 1 WCU 2 WCU

Dual-key sharded design

Partition key value User ID Possible values Uniformity Many Good Status code Few Bad Timestamp, rounded to day, hour, etc Few Bad Device ID, uniform traffic Many Good Device ID, a few “hot” devices Many Bad

Query by key vs. Scan all

Secondary Indexes

Global Secondary Index

Local Secondary Index

Size Shape Velocity

Idempotence and Concurrency

Webhooks Amazon SQS Amazon SNS Amazon Lambda

Real Life

Table Partition Key OrderEvents messageId PendingOrders clientId Failures messageId Sort Key messageId Size RCUs WCUs 3GB 5-100 5-500 56KB 5-500 5-500 68KB 5-50 5-50

Ran out of compute units

Not enough time to retry

Race conditions

Status ConditionExpression created #id <> :id and #did <> :did started #status = :current and #status <> :newStatus queued #status <> :final and #status <> :newStatus finished

Search and filter

More race conditions

Status Step UpdateExpression created 1 started 2 SET #status = :newStatus, #step = :step queued 4 SET #status = :newStatus, #step = :step error 128 SET #status = :newStatus, #step = :step finished +1 SET #status = :newStatus, #step = #step + :step

Hard 10GB limit

Tips

RTFM!

It ain’t a lock

Bind attribute names

Handle ConditionalCheckFailed errors and retry

Use CloudFormation

Auto-scale

X-Ray

Questions?

Thank You! http://compwright.com/talks/dynamodb-in-real-life @compwright jonathon@compwright.com 864-245-5885