DEV Community

Joud Awad
Joud Awad

Posted on

DynamoDB Client API Tutorial: Query, Pagination, Cost Explained

There is no SQL in DynamoDB.

No query language, no syntax to memorize, no planner deciding how your request gets run. You import a client and you call a method.

In Postgres, "give me one row" and "give me a thousand rows" are the same SELECT with different clauses, and the engine works out the rest. In DynamoDB those are different methods and you're the one choosing. GetItem for a single item by its key. BatchGetItem for up to 100 of them. Query for a run of items under one partition key. Scan for when you've given up and want the whole table.

The method name is the operation. That's the shift people miss coming from SQL: you're not composing a statement, you're picking an action. One item or many, atomic or not, read or write. Three decisions, and the entire client API falls out of them.

What you do have to learn is the cost, because it isn't hidden behind a planner any more. 4 KB read blocks, 1 KB write blocks, and a round-up rule that makes a 200-byte item cost a full block. A strongly consistent read costs double an eventual one. A read inside a transaction doubles again. Once you know which method you called, you can price the call before you run it.

So I ran every one of them on camera, from real NestJS code, with the consumed capacity on screen next to each call.

https://youtu.be/JeyZ-kN0H7Y?si=ZkvqVIC1TCjCX06k

Top comments (0)