Do i need a webserver with datomic cloud for a typical web application?

Given a solo topology setup, is it recommended to also run a web server? As i understand it the Ion > AWS lambda would be handling everything i would need a server for:

  • opening network socket,
  • listening for requests
  • calling the handler

Though, now that I’m typing this, I’m not sure it would be isolating requests in their own thread.

Assuming they do overlap, which I’m still obviously thinking through, what would be the recommendation for local development then? Understandable, that’s mostly up to me, but i’m curious what others have done. My current idea would be to run the web server locally.

I’m developing a Clojurescript app at the moment with just Datomic Cloud Ions, API Gateway and Cognito for auth. Early days yet but I don’t see where I will need a server. The app assets (HTML, CSS, JS etc) are served by CloudFront+S3. There were a few tricks to get API Gateway hooked up so let me know if you get stuck.

Hey friends, have a look at this pedestal sample for inspiration.

It was written before dev-local but should work fine with that too.

Also, when you outgrow lambdas, it should also work with http-direct.

Thanks James if you have anything written up on your setup (cloudfront+s3) i would love to take a look. I’m using Rum and so the initial load of the html/JS might need to be handled in the lambda. Though i suppose I can cache any static load page in s3.

Thanks Jplane, i’ll take a look. I can use all the examples I can get.

No, you do not need a webserver with datomic cloud. You may use AWS API Gateway and I believe that is the recommended way to do things. It’s what I did when following the documentation. Ions Tutorial | Datomic

Also, the pedestal sample referenced earlier uses Pedestal Ions, which has a nice 1-2-3-4 steps laid out on the GitHub page at GitHub - pedestal/pedestal.ions: A Pedestal Interceptor Chain provider for Datomic Ions. I found this useful and modeled it directly in my code.

Last, I did setup a dev server - this took me a while to figure out how to do - using dev-local’s divert-system and pedestal’s builtin webserver io.pedestal.http/start. However, I found that this wasn’t necessary for most of my local development. I could just call my functions directly from the repl. With dev-local, the datomic queries can be tested like this and many http requests can be tested since they are plain old data going to pure functions! It gave me a little mind blowing moment. I suggest trying how much you can develop and test without starting up a dev server. I’m coming from worlds like RoR, Flask, and other places where this would be impossible, so my mind went straight to “setup a dev web server”. Only after struggling with this for a while did I realize… “I don’t need a dev web server to test what I’m wanting to test. Perhaps that’s why this doesn’t exist right out of the box.”

Of course, there is still value in seeing what the final app looks like with everything together.

2 Likes

Hello Jason, Thank you for the write-up regarding dev-local. Question on dev-local’s divert-system and pedestal’s builtin webserver io.pedestal.http/start . Could you provide some details? I keep getting a .lock error and am not able to run both nRepl & Jetty Server with dev-local. Any information is much appreciated. Thanks in advance.

Hi Krishnan, it would take me some digging to figure out what I did. That was over a year ago. Datomic’s dev-local divert-system should be Google-able. If you’re getting lock errors related to file based locks then I would do the standard debugging of lock files - shutdown all programs, delete the lock files, start the services back up one at a time, note which program gives the error and why (port conflict, starting a service twice, etc.). I hope this helps some. Sorry I can’t be of more help. I don’t want to spend an hour digging through my old project figuring out what I did.

Hi Jason, Thank you for the response and the hints. I have done all of the items you mentioned, but no luck yet. Pedestal/Jetty or the nRepl, whichever is started first locks the storage location. Therefore, the Cursive/nRepl or the Jetty server won’t work at the same time with dev-local. Maybe some changes in deps.edn or logging, I don’t know yet.

Thanks again.

Ok, yeah, it sounds like the commands you’re running are starting two instances of Clojure where both of them are using dev-local with the same file for local storage. That’s not possible. It seems like what you’re trying to do is have one instance run a local web server (Jetty with Pedestal and dev-local) and another instance with a REPL so you can type Clojure code. Am I right? If that’s so, know that the second instance - the one with the REPL - doesn’t need to load your program. It just needs to connect to the remote REPL server started by the first instance.

Try this:

  1. Run Pedestal/Jetty with a REPL server and dev-local.
  2. Connect to that REPL server with clj but without loading all your code (and therefore, without starting dev-local a second time).

You can then run code against the first instance, load code, etc… I don’t recall off the top of my head how to connect to a remote REPL from the command line. You’ll have to look that up, but I know it isn’t necessary to load your code to do it.

1 Like

Try this for connecting to the nrepl: nREPL Clients :: nREPL
Of course you also need to be sure the first instance starts the nrepl server properly. That’s a one liner. Something like (defonce server (start-server :bind "172.18.0.5" :port 4001)) See nREPL Server :: nREPL

1 Like

Hi Jason,

Thank you for the clear explanation. It worked! This is what I did.

First, started the Jetty sever (am using Pedestal) → clj -M:dev:jetty
Then, → (require '[nrepl.server :refer [start-server stop-server]])
Then, → (defonce server (start-server :port 54400))
Then, → (require '[XXXX.server :as server])
Then, → (def XXXX-service (server/run-dev 9091))

My Cursive repl is configured to access 54400! Hope this will help someone looking for a fix.

Thanks again to Jason for the information.

1 Like