English3000

English3000

I’m currently reading through Functional Web Development in Elixir. It walks the reader through how to build an app using a stateful OTP server in place of a database.

When one first begins a project, a main benefit of using a stateful server, the author @lance posits, is it decouples and separates one’s design from one’s database tables. Because of Elixir’s concurrency, Phoenix’s bandwidth and Presence feature, and OTP’s fault tolerance and high-scale distributability, the stateful server is now a viable alternative to a database, reducing code complexity and app latency.

What I’m wondering:

  1. What are the bounds of a stateful server? I.e. What level of usage requires the switch to a database?

  2. What does that transition look like? For example, could one still keep pieces of the stateful server for speed (where throughput isn’t as much an issue)?

  3. In production, wouldn’t best practice be for the stateful server to offload state to the database, and for it to fetch the most recent state from maybe Redis, were there a system-wide reboot? I.e. Is OTP truly reliable enough for a production app not to require some sort of fallback for the state?

Showing Posts 1 to 4

wmnnd

wmnnd

Using a database (whether it’s a traditional SQL database or an OTP database such as Mnesia) makes sense when you want to persist data beyond application restarts. This might be true for parts of your data or all of your data, depending on your application.

I personally tend to just use an SQL database right away because it usually fits my application’s need anyways.
But if that’s not the case, you can always add a persistence layer to your stateful application that takes care of storing data when required and loading it when it gets restarted. With this approach you can leave most of your code unchanged and simply add code for storing/retrieving in/from the DB to your own state management functions.

dom

dom

A database is useful to store dynamic state that can’t be reconstructed, for instance user input. Things that can be rebuilt, or queried from another service, often don’t need to go in DB. See:

blatyo

blatyo

Conduit Core Team

Another consideration is deployment. If you have persistent state in your application, you’ve essentially made your application a database. The way you database is very different from the way you deploy an application with no persistent state. There’s a concept called Pets vs Cattle, where Pets are special applications that need a lot of criteria to be true. For example, if you’re using disk based persistence, then if you roll that application, you’ll want it to have access to the same disk on reboot. Cattle, applications without persistent state, can be killed and booted anywhere.

dimitarvp

dimitarvp

See Phoenix Contexts for reference. You can make your own modules and functions that do reading, querying, writing and deleting and the consumer would be none the wiser on how is the data stored. So you can code according to your requirements from day one really.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
nseaSeb
AcmeScript — Writing JS hooks as if I were still using Elixir I’ve been having fun building a little something over the last few days: Ac...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews