Build ‘Availability First’ Systems with Elixir + DataStax Astra
Why DataStax Astra and Elixir? Elixir is to programming languages what Apache Cassandra™ is to databases: fault tolerant with features that prioritize scale without sacrificing performance or resilience.
Elixir was designed to build fault tolerant distributed systems. It starts with a functional approach to programming, no shared state, and easy to distribute work. First class supervision trees for sub-tasks add exceptional fault tolerance to the mix. OTP, a set of tools that Elixir inherits from Erlang, levels this mix up by letting us distribute that system. The sum of these parts is: a set of fault tolerant app servers, tightly integrated with one another, sharing information and events.
Astra is the ideal datastore for this type of system. Built on Apache Cassandra, Astra prefers availability to immediate consistency (think single millisecond latency). What does that mean to developers? The elimination of deadlocking behavior that makes systems hard to scale. It gives us a data layer that will always respond to the application layer. Ultimately, we want lots of little cubbies for our data that are always available.
Think of Astra + Elixir as an Availability First (AF) architecture. Availability First embraces concurrency locally and across entire app clusters. It means eliminating things like serial iterators, global state, locks at the db level, and global serial processes like shared iterators. Together, Astra and Elixir provide a platform where we can build without these limitations. It creates systems that are scalable and durable AF. When more coordination of our data is required, there are often ways to support that in AF systems. Things as complicated and critical as major global banking transaction hubs have been built on availability first databases.
DataStax recently released an Elixir library for Astra’s REST, GraphQL, and Document JSON APIs, including a reference chat app that makes the most of the Astra + Elixir stack. When a user logs in, the app pulls message histories down for the “threads” they follow directly from Astra. Next they join Elixir/Phoenix channels for each thread to allow them to be reactive to new messages instead of constantly polling the database. This matches Cassandra’s ability to write at high velocity with Elixir’s ability to coordinate across a cluster of application servers.
The reference application shows how you can use both the REST and Document APIs available in Astra. Tabular data is used for message histories while each user has a JSON document that keeps information about the threads they follow. Grab a copy of the Example code to see this in action, or use the Elixir package to start working with the AF stack today.
Get started today by:
- Launching the Sample App https://github.com/DataStax-Examples/astra-loom
- Grabbing the Elixir package and docs for your own project
- Grabbing the Docker container, which includes everything https://hub.docker.com/repository/docker/omnifroodle/astra-loom