Skip to content

Durable Programs

Durability

Membrane allows you to build functionality very quickly because, among other things, you don’t need to worry about persistence. Each program is its own database.

Programs run in a durable runtime that transparently and efficiently persist its state to disk. This is different from other serverless environments, where programs can only run for a limited amount of time, typically a few minutes, because CPU and RAM are expensive and servers need to be able to restart at any time.

In contrast, Membrane is continually and transparently persisting changes to the program’s entire memory heap so that when a program goes idle, it doesn’t consume any CPU or memory, and our servers can be restarted without you noticing. When a program needs to do something again, for example, handle an HTTP request, Membrane lazily restores only the parts of the heap that are needed so that “cold-starts” are fast.

Unlike other serverless runtimes, Membrane programs:

  • Don’t need to persist data to a database or file.
  • Can run forever and will never be killed due to timing out.
  • When you change the code, the new code continues the execution with the same state.

I/O

The main challenge we faced when designing Membrane was how to handle I/O.

Conventional programs have state that simply cannot be persisted to disk. For example, socket connections or open file handles. To solve this, all I/O in Membrane is externalized, meaning that the programs don’t directly interact with the outside world by opening sockets. Instead, they write the request to its write-ahead log and then Membrane takes care of executing it.

Replays and time travel

Thanks to our write-ahead log and our deterministic JavaScript runtime, the entire history of the program can be replayed. Which means you can go back in time, inspect the state, debug errors after the fact and so on. These features are currently being worked on. Subscribe to our mailing list or join us on Discord to stay up to date.

Limitations

Membrane is not a silver bullet. One important limitation to keep in mind is that, because of its stateful nature, programs cannot be scaled horizontally. However, scaling is oftentimes not necessary! Learn more about when to use Membrane.

Another limitation is that, due to our I/O model, you currently cannot stream network responses. This is something we’re working on fixing though! So, stay tuned.