Backend for Web Development using Clojure/ClojureScript
Asked Answered
C

3

6

I'm familiar with developing desktop apps in Clojure (written a multithreaded interactive visualization system). However, I'm fairly new to Web development using Clojure.

I plan to use Clojure on the server for handling logic; and ClojureScript for handing client side work. However, I don't know what to use for my database server. Should I use something like Monogodb? or Hadoop? Or .... ?

The app is something very simple; a basic forum. Total number of concurrent users will be < 100 at a given time. One thing that is important to me is the ability to easily backup / data consistency -- it's very very important to me that I can easily make daily backups (and not lose all the data.)

Thanks!

Checkrein answered 14/4, 2012 at 4:9 Comment(3)
Is the interactive visualization system public? I work on Clojure/ClojureScript data visualization with the C2 library, and I'd be interested to see other Clojure programs in that domain.World
@Kevin: sorry, this entirely private; though we may be able to release some of the GUI elements.Checkrein
Datomic is written in Clojure, by creator of Clojure. May be you should use Light Table which was written in ClojureScript for development :)Republic
F
6

You can use many databases; if the database has an API for Java, you should be good to go. MySQL, MongoDB, Postgres, Hadoop… and more.

For a nice overview of the webstack in Clojure, check out brehaut's article on the matter.

For getting up and running quickly with Clojure and ClojureScript, try ClojureScriptOne.

There are many ways to write what you want to write; if you're already familiar with Clojure, it shouldn't be too hard to get going.

Fining answered 14/4, 2012 at 5:17 Comment(2)
BTW, do you know what backend ClojureScriptOne is using?Checkrein
It's using Ring/Compojure/Enlive as it's server-side stack. There's no database involved in the app, though you could of course add one.Fining
H
5

Haven't used it myself, but Datomic ( http://datomic.com/ ) looks great for anyone coming from Clojure.

Hittite answered 22/5, 2012 at 3:48 Comment(0)
D
1

Datomic is an amazing database, and I'd highly recommend it. It has many features which set it apart from other database systems:

  • Like Clojure's data structures, it's persistent, meaning that by default, adding new facts to the database doesn't delete old facts, allowing you to query the state of the database at a previous point in time, enhancing audit-ability and assistance in debugging.
  • The underlying Entity Attribute Value (EAV/triple) data model (at least partly inspired by RDF & the Semantic Web), is extremely flexible, allowing you to express arbitrary graph structures and effortlessly deal with polymorphism.
  • The query language is flavor of Datalog, a sort of pattern matching based query language strictly more expressive than SQL and the like in that it can do recursive queries, making it particularly well suited for dealing with graph data/queries.
  • In addition to Datalog queries, there's a pull api, which let's you pull data out of the database more simply using a GraphQL like expression which specifies the shape of a document-like structure you'd like to pull out of the database. These queries can even be used from within the :find clause of a Datalog query.
  • You can use Clojure functions from within your queries.
  • The indexing system is very smart and more or less automatic, in stark contrast with the work that typically goes into tuning SQL databases for performance.
  • Transactions go through a different API/function call than queries, meaning that the number one security risk identified by OWASP (SQL injection) is literally impossible in Datomic.
  • The transactor/read-replica design makes it super easy to scale reads/queries, while keeping pressure off the transactor.
  • It's fun as hell.

One of the things worth pointing out here is that by embracing the EAV data model and datalog/pull queries, Datomic ends up having structural flexibility closer to that of a NoSQL database, while still being fundamentally relational, and even more expressive in it's relational queries than SQL.

It's amazing and you should absolutely give it a shot. It will melt your brain a little. In the good way.

It's also worth noting that it's popularity has inspired a number of successful open source projects, so the underlying approach is not going anywhere any time soon:

  • DataScript: In memory clj/cljs partial implementation
  • Datahike: Fork of DataScript which queries over on disk indices, meaning you don't have to keep everything in memory to query
  • Mentat: Mozilla project trying to make a Datomic-alike for a Mozilla project
Dariadarian answered 28/1, 2019 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.