Keeping a top 20 in azure table storage

Azure Table Storage is a cheap, fast and easy to use data storage system.

It does have it’s limitations.

All data has two keys partition key and row key which need to be unique in combination.

The best way to guarantee the return of say the latest 20 entries is to use  DateTime.MaxTicks – DateTime.Now.Utc (in a 19 digit left padded with zeros format) as the row key.

This means that reading the data you can just fetch the items by partition key with a limit on how many rows to return.

The difficulty will come in keeping the data from filling up the storage account if you never clean up.

I would suggest that when the data is read back if you get the maximum number of items that you queried then perform a second query to return 100 rows older than the oldest row that you have just fetched and delete them in a single async batch. This is the optimum delete size (as 100 is the max batch size for azure table storage).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s