Skip to content

Dynatomic is a library for using dynamodb as an atomic counter

License

Notifications You must be signed in to change notification settings

tylfin/dynatomic

Repository files navigation

Dynatomic

Build Status Build status Go Report Card GoDoc Coverage Status MIT license CodeFactor Mentioned in Awesome Go

Dynatomic is a library for using dynamodb as an atomic counter

Motivation

The dynatomic was written to use dynamodb as a quick and easy atomic counter.

The package tries to serve two unique use cases:

  • Unique, fast real-time writes, e.g. user visits to a page or rate limiting
  • Large number of asynchronous writes that need to be eventually consistent, e.g. API usage by a client for billing

Usage

Basic usage:

// Initialize the dynatomic backround goroutine with a batch size of 100,
// a wait time of a second, an AWS config and a function that will
// notify the user of internal errors
d := New(100, time.Second, config, errHandler)
d.RowChan <- &types.Row{...}
d.RowChan <- &types.Row{...}
d.RowChan <- &types.Row{...}
...
d.Done()

Dynamo will update accordingly.

For example if you write the rows:

Table: MyTable, Key: A, Range: A, Incr: 5
Table: MyTable, Key: A, Range: A, Incr: 5
Table: MyTable, Key: A, Range: A, Incr: 5
Table: MyTable, Key: A, Range: A, Incr: 5

Then MyTable Key A, Range A will now show a value of 20

Development

To copy the repository run:

go get github.com/tylfin/dynatomic

Then you can run the full test suite by doing:

docker-compose run dynatomic

Contributing

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug
  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it)
  3. Write a test which shows that the bug was fixed or that the feature works as expected
  4. Send a pull request and bug the maintainer until it gets merged and published

About

Dynatomic is a library for using dynamodb as an atomic counter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published