README.md

# Aphora
[![Build Status](https://travis-ci.org/schicksalapp/aphora.svg?branch=master)](https://travis-ci.org/schicksalapp/aphora)
[![Hex.pm Version](https://img.shields.io/hexpm/v/aphora.svg?style=flat)](https://hex.pm/packages/aphora)

Aphora is a system do distributedly generate unique IDs without any coordination. It is similiar to [Snowflake](https://github.com/twitter-archive/snowflake/tree/snowflake-2010), but generates ASCII sortable strings instead of integers.

It uses 72 bit long `Binaries` which get encoded to 12 characters long `Strings`.  
An Aphora ID is composed of:
* `45 Bits Timestamp` with millisecond precision. It gives up to 1115 years with a custom epoch.
* `5 Bits Datacenter` allows up to 32 different datacenters.
* `10 Bits Worker` allows up to 1024 different processes/workers/machines within a datacenter.
* `12 Bits Counter` allows for 4096 Aphora IDs to be generated each millisecond. Aphora also protects against rollovers to happen within the same millisecond.

Just like [Snowflake](https://github.com/twitter-archive/snowflake/tree/snowflake-2010), Aphora protects from non-monotonic clocks, by refusing to generate timestamps until it gets provided with a time equals or after the last generated ID.

## Installation

The package can be installed by adding `aphora` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:aphora, "~> 0.3.2"}
  ]
end
```

The docs can be found at [Hex](https://hexdocs.pm/aphora).

## License

Aphora is licensed under the [Apache License 2.0](LICENSE.md).