stefan_z

stefan_z

Chord - A Flexible Library for Real-Time Context Management 🎵

Hello everyone!

I’m excited to share Chord, an Elixir library I’ve been working on that simplifies real-time context management and state synchronization for distributed and real-time applications. It’s designed to be both flexible and efficient, with an API that’s easy to use and integrate.

Why Chord?

Chord was born out of the need to streamline state synchronization and lifecycle management for real-time systems, where contexts change frequently. Whether you’re building a collaborative application, a real-time dashboard, or a messaging system, Chord provides the tools to manage state seamlessly.

Key Features

  • Context Management: Create, update, synchronize, and delete contexts effortlessly.
  • Delta Tracking: Minimize data transfer by only sending changes.
  • Flexible Backends: Use ETS (in-memory) or Redis (distributed) for storage.
  • Partial Updates: Update specific fields within a context without replacing the entire structure.
  • Customizable Cleanup: Automatically or manually clean up expired data.
  • Context Export & Restore: Export contexts to external storage or restore them when needed.
  • Pluggable Architecture: Use custom modules for time providers, delta formatting, and external state restoration.

Open to Feedback

This is the first release of Chord, and I’d love to hear your thoughts! Is there something you’d like to see added or improved? Are there edge cases I haven’t considered? Your feedback would mean a lot and help make Chord even better.

You can find the project on Hex.pm and GitHub:

Thank you for checking it out, and I’m looking forward to hearing your feedback! :raising_hands:

Most Liked

dimitarvp

dimitarvp

Thanks for posting this. Quick feedback: a few more examples, and more real-world-like, would be very appreciated.

l3nz

l3nz

Agreed - not sure what/where it is supposed to be. What is a “context”?

l3nz

l3nz

If I were you I’d use that as theproject description on GitHub :slight_smile:

stefan_z

stefan_z

Hi @l3nz,

I see what you mean about it resembling an Elixir Agent, but there are a few key differences and advantages that Chord brings, especially with deltas and their management:

  • Flexibility in architecture: While Agents are a stateful abstraction, Chord works in both stateful (via GenServer) and stateless modes (direct calls to backends like Redis or ETS). This flexibility makes it easier to adapt Chord to a variety of use cases.
  • Efficient state updates with deltas: Instead of syncing the entire state on every update, Chord tracks the changes (deltas). This minimizes bandwidth usage and makes real-time synchronization more efficient, especially for larger datasets or high-frequency updates.
  • Delta retention and expiry: Chord allows you to configure how long deltas are retained and when expired deltas should be cleaned up. This gives you fine-grained control over memory and storage, which is something Agents don’t provide by default.
  • Decoupled backend support: Chord allows you to plug in different backends, such as ETS for in-memory storage or Redis for distributed setups. This makes it highly scalable, which can be challenging to achieve with simple Agents.

Let me know if there are specific points you’d like to see covered more in-depth in the docs! :blush:

stefan_z

stefan_z

Hi @dimitarvp, thank you so much for your thoughtful feedback, I truly appreciate it! :blush:

Initially, I chose not to include old_value for the :removed action by default, instead offering the option to implement a custom delta formatter to adapt deltas to specific needs. However, after reflecting on your suggestion, I completely agree with you. Adding old_value to the :removed action provides greater flexibility and aligns better with the behavior of other actions like :modified. I’ll be incorporating this change in the next update.

Regarding your question, a “backend” in Chord simply refers to the underlying data storage mechanism, such as ETS or Redis.

As for “context” versus “state,” I understand your perspective, and you raise a great point. The term “context” was chosen to highlight the library’s flexibility and adaptability, aligning with its design goals. While “state” might feel more universally intuitive, “context” reflects the broader intent behind Chord’s functionality. I really appreciate your input, it’s always valuable to revisit and reflect on these choices.

Thanks again for your insights! Let me know if there’s anything else you’d like to discuss or suggest, I’d be happy to hear it!

Where Next?

Popular in Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
mathieuprog
Hello :wave: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First and fore...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
zorbash
I created Kitto a framework for dashboards inspired by Dashing. [demo] The distributed characteristics of Elixir and the low memory foo...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

Sub Categories:

We're in Beta

About us Mission Statement