Khawaja Shams Profile picture
Apr 3, 2023 17 tweets 5 min read Read on X
A customer was considering leaving #dynamodb due to costs.

@pj_naylor and I helped them save half a million dollars per year with one simple, magical, optimization.

Want to save DynamoDB costs like a pro? Let’s start with some background…
1\ DynamoDB writes are 20x more expensive than reads. If you have 5 GSIs, you may be doing 6 writes every time you write a single item into a DynamoDB table.

The 20x is not a typo. More on that soon.
2\ The read & write request units are a bit complex. Let’s simplify, @momentohq style.

DynamoDB writes are charged in 1KB increments.

If you write 100 bytes, you pay for 1KB. 1.1KB => 2KB.

Writing exactly 1KB items costs $1.25/GB (on-demand), but….👇
2b\ 100 byte item cost $12.5/GB (on-demand) to write to DynamoDB. 1.1KB items cost $2.27/GB to write.

100 byte item with 1 GSI costs $25/GB to write (on-demand).

Moral: item size has a profound, under appreciated, impact on your DynamoDB costs.
3\ Reads are measured in 4KB increments. This is why even though write requests are 5x more expensive than read requests, perfectly sized reads (4KB) are 20x cheaper than perfectly sized writes (1KB).
4\ To help our customer save half a million / year, the biggest optimization was to reduce their 1.2KB objects to be reliably under 1KB.

This is easier than it sounds!
1. Use binary data types + compression
2. Use numbers / bytes to express dates
3. Use shorter attribute names
5\ There are lots of ways to easily reduce your dynamodb item size.

The key is to recognize that dropping your item size by 10% can have a meaningfully larger impact on your total DynamoDB bill - especially if you have a write heavy workload!
6\ Reducing the number of attributes projected in your GSI can reduce the GSI item sizes to under 1KB too.

1. Optimize write costs first. If you’re read heavy, try @momentohq .
2. Reduce item sizes to be closer to 1KB increments.
3. Reduce unnecessary GSIs / reduce item sizes
7\ Next up, you may be tempted to go to provisioned capacity to save money over on-demand.

Is provisioned capacity actually cheaper? It comes down to one thing: utilization.
8\ DynamoDB provisioned capacity is sold in WCUs and RCUs (Write/Read Capacity Units). A WCU can write a 1KB object per second & costs $0.00065/hr

Let’s simplify, @momentohq style. Provisioned writes cost $.18/GB to write data, which is a steal over $1.25/GB on-demand. Right?
9\ Yup! DynamoDB provisioned capacity is 1/7th the cost of on-demand.

But you pay for this capacity whether you use it or not.

For provisioned capacity to be cheaper, utilization needs to be at least 15% - every single second.

This is harder than it sounds for spiky traffic!
10\ If your traffic follows a predictable pattern, you could use autoscaling to help right-size your provisioned capacity.

Setting up autoscaling is tedious - & you have to keep an eye on it… but, if your traffic patterns are stable, it is magical for improving utilization.
11\ If your load is not stable, you are likely better off using on-demand.

As counter intuitive as it may sound, I have seen numerous customers *save* money by going on-demand! It scales faster too - and it makes your system more robust.
12\ But wait. You can make your provisioned capacity billing even cheaper!

3 year reservations on WCU save 87% on IOPS! 80% for 1 year.

If you commit the capacity, you get much larger discounts than EC2 RIs on DynamoDB.

But is it worth it? Comes down to utilization 👇
13\ The reserved capacity is sold in the increments of 100s of WCUs/RCUs. The utilization here is even harder to get right!

You have to utilize all 100 of the WCUs/RCUs that you purchase for the year AND you have to utilize each second of throughput throughput the year, but…
14\ Reserved throughput that is consistently provisioned may end up being meaningfully cheaper and meaningfully simpler compared to complicating provisioned capacity w/ autoscaling!

If your usage is predictable, you can skip the autoscaling.
DynamoDB rocks! You can tune it to cost way less.

Have more questions? Want to optimize even more? Reach out to me or @pj_naylor.

Or just post your question on twitter. Lots of DynamoDB fans & experts ready to help you make the most of a great service.

Paging @Alexbdebrie

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Khawaja Shams

Khawaja Shams Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @ksshams

Mar 21
RIP Redis: How Garantia Data pulled off the biggest heist in open source history.

Detailed blog linked - but checkout the thrilling story of this heist in 🧵first 👇

gomomento.co/redisos
Image
Redis launched in 2009 as a labor of love by Antirez. It won the hearts of developers globally - and it is still one of the most loved databases brands in the world.

In 2011, AWS launched ElastiCache Redis, & Garantia Data, an early stage startup, launched managed Redis. Image
Garantia Data had little to do with the development of Redis - and it was basically the same concept as ElastiCache, except ElastiCache grew like wildfire. Garantia - was a scrappy startup - not ready to give up despite the modest growth in comparison 👇 Image
Read 14 tweets
Oct 30, 2023
#DynamoDB is the most magical AWS Service, so @alexbdebrie & I decided to put on a magic show w/ @momentohq! #ddb_magic

Our favorite DynamoDB magic numbers in🧵will help you become an expert table magician by learning key internals!

What's your favorite magic number? Image
6.94
On-Demand IOPS cost 6.94x provisioned iops, but on demand is often cheaper! Why?
1\ 6.94 assumes 100% utilization. Nobody gets 100% utilization IRL!
2\ Autoscaling requires a predictable load cycle & fine tuning
3\ You can mix & match.
#ddb_magic another framing 👇
Image
Image
6.94
Instead of focusing on the price delta being 6.94x for provisioned capacity v On Demand, another framing is “what is the utilization of my IOPS?”
If your utilization is above 14.4%, use provisioned! Otherwise, OD

but #ddb_magic, how do you calculate utilization? 👇 Image
Read 16 tweets
Apr 26, 2023
DynamoDB GSI (Global Secondary Index) are magical if used properly.

A primer 🧵 on how they work to help you make the most of them…

👇

A GSI is basically another DynamoDB table. A table by any other name would have just as many partitions…
0\ You are listening to a DynamoDB Stream on table A. Whenever you see an item with a specific attribute, you insert it into table B with the attribute as the primary key.

👆 this is a GSI in a nutshell! Internalize this - and GSIs will make 💯 more sense..
1\ The only differences b/w what’s illustrated above & a real GSI is that a) GSI is managed for you, b) it gets updated much faster, c) it will prevent you from getting too far behind.

The rest of it is exactly the same. So what does that mean for GSIs?
Read 17 tweets
Apr 20, 2023
Getting started with just 5 lines of code was pretty neat, but how about zero?

Momento Console is here!

@dymxzvf personally worked on this alongside our awesome deveco team. DM us for early access to upcoming features.

#launch #serverless

gomomento.co/3Af3iH8
Getting started on the @momentohq console is as simple as using your existing Google/Github accounts to sign-on! Image
If you are a new customer, you may not have any caches - but not to worry, it takes 10 seconds to make one! Image
Read 4 tweets
Jan 30, 2023
#DynamoDB strongly consistent reads are magical, but not for the reason most of us think.

SC reads have higher latencies, lower availability, and cost more - but worth it if you use them for the right reasons.

🧵👇explains what they are & how to unlock their real power!
0\ Primer: Doug Terry does a phenomenal job explaining the various consistency models through an illustrative exercise:
microsoft.com/en-us/research…

Read this first to become a consistency ninja!
1\ The most common mistake I see with DynamoDB SC reads is assuming it’s fresher than it is. Suppose you want to increment a counter: an SC Read tells you X=2 - you *cannot* set X=3 because another thread may have already changed it in the meantime. Use Conditional Puts instead!
Read 18 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(