---
title: "Discussion on \"Simple Atomic Counter with DynamoDB and API Gateway\" | Hashnode"
description: "Discussion on \"Simple Atomic Counter with DynamoDB and API Gateway\". A web application often needs a central counter. We have several simple use-cases like the member id for a registration application. Or the amount collected on a sales application - there are many that we all have seen. We have to make sure the concu..."
url: "https://hashnode.com/posts/simple-atomic-counter-with-dynamodb-and-api-gateway/5fb7db99ba1e08716c77f6eb"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Simple Atomic Counter with DynamoDB and API Gateway](https://blog.thewiz.net/simple-atomic-counter-with-dynamodb-and-api-gateway?utm_source=hashnode&utm_medium=feed)

A web application often needs a central counter. We have several simple use-cases like the member id for a registration application. Or the amount collected on a sales application - there are many that we all have seen. We have to make sure the concu...

Nov 20, 2020 · 3 min read · blog.thewiz.net  
Updated Feb 17, 2024  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#dynamodb](https://hashnode.com/tag/dynamodb)

## Written by

[Vikas Solegaonkar](https://hashnode.com/@solegaonkar)

@solegaonkar · Mumbai, India

  
[View profile](https://hashnode.com/@solegaonkar)

Vikas Solegaonkar

## Responses 1

Markdown supported · ⌘↵ to post

[Owain McGuire](https://hashnode.com/@owain68)

[Nov 25, 2020](https://hashnode.com/posts/simple-atomic-counter-with-dynamodb-and-api-gateway/5fb7db99ba1e08716c77f6eb/comment/5fbe283dd9a105315340e572)

I did hunt around a while back to find this as a SaaS application. Couldn't find it. With an authorizer, you could launch!

Under heavy workload on a specific counter, this is going to hotspot the item in DynamoDB. As it has to be atomic, there is no way to cache (check you haven't got any caching in API Gateway) and the usual Scatter-Gather pattern defeats the atomic nature too.

Fun though.

[Vikas Solegaonkar](https://hashnode.com/@solegaonkar)

[Nov 25, 2020](https://hashnode.com/posts/simple-atomic-counter-with-dynamodb-and-api-gateway/5fb7db99ba1e08716c77f6eb/comment/5fbe283dd9a105315340e572#reply-5fbe5892ba8f5f33d5150986)

That's a good idea. Will push this as a public API. API Gateway caching can be disabled. I have not tested this under Very High load - But it worked pretty well in 100 hits per second

[Owain McGuire](https://hashnode.com/@owain68)

[Nov 25, 2020](https://hashnode.com/posts/simple-atomic-counter-with-dynamodb-and-api-gateway/5fb7db99ba1e08716c77f6eb/comment/5fbe283dd9a105315340e572#reply-5fbe700408c16c34b89c41a4)

[Vikas Solegaonkar](https://hashnode.com/@solegaonkar) there might be a little domain model here:

user has a clientId (PK) user can create multiple counters (SK) user can admin a counter, e.g. suspend, delete, and set value (reset to zero). each counter has a userkey without the admin privileges, getCounter (reads current value need to set TTL so there is no caching), incCounter (returns the new value with a timestamp) users could be internal services: orders, customers,

Add a billing mechanism for clients and their users and "this time next year we will be millionaires". [youtube.com/watch](https://www.youtube.com/watch?v=qp5hxHPlTq8)
