GithubHelp home page GithubHelp logo

berrondo / prevayler-clj Goto Github PK

View Code? Open in Web Editor NEW

This project forked from klauswuestefeld/prevayler-clj

0.0 0.0 0.0 40 KB

Absurdly fast, 100% transparent, ACID persistence in under 100 lines of Clojure.

License: BSD 3-Clause "New" or "Revised" License

Clojure 100.00%

prevayler-clj's Introduction

Clojars Project

Feature

Write your business logic as a pure event-handling Clojure function, without any database complexity. It will be much simpler and orders of magnitude faster.

Prevayler takes care of persistence.

See what's new in Prevayler4.

Usage

  • Get enough RAM to hold all your data.
  • Implement the business logic of your system as a pure event handling function. Keep any I/O logic (accessing some web service, for example) separate.
  • Guarantee persistence by applying all events to you business system through Prevayler, like this:
(defn my-business [state event timestamp]            
  ...)                                   ; Your business logic as a pure function. Returns the new state with event applied.

(with-open [p1 (prevayler! {:business-fn my-business})]
  (assert (= @p1 {}))                    ; The default initial state is an empty map.
  (handle! p1 event1)                    ; Your events can be any Clojure value or Serializable object.
  (handle! p1 event2)
  (assert (= @p1 new-state)))            ; Your system state with the events applied.

(with-open [p2 (prevayler! my-business)] ; Next time you run,
  (assert (= @p2 new-state)))            ; the state is recovered, even if there was a system crash.

How it Works

Prevayler-clj implements the system prevalence pattern: it keeps a snapshot of your business state followed by a journal of events. On startup or crash recovery it reads the last state and reapplies all events since: your business state is restored to where it was.

Shortcomings

  • RAM: Requires enough RAM to hold all the data in your business state.
  • Start-up time: Entire state is read into RAM.

Files

Prevayler's default file name is journal4 but you can pass in your own file (see tests). Prevayler-clj will create and write to it like this:

journal4

Contains the state at the moment your system was last started, followed by all events since. Serialization is done using Nippy.

journal4.backup

On startup, the journal is renamed to journal4.backup and a new journal4 file is created. This new journal will only be consistent after the business state has been written to it so when journal4.backup exists, it takes precedence over journal4.

journal4.backup-[timestamp]

After a new consistent journal is written, journal4.backup is renamed with a timestamp appendix. You can keep these old files elsewhere if you like. Prevayler no longer uses them.


"Simplicity is prerequisite for reliability." Dijkstra (1970)

prevayler-clj's People

Contributors

klauswuestefeld avatar kalecser avatar bamboo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.