dogweather

dogweather

Fast Ruby/Rails interop?

The answer is probably no but I thought I’d try:

Is there a way to write Elixir functions that can be invoked by a Rails app as efficiently as a Ruby library? Most of my new Rails development is in the form of Ruby libs for parsing and string manipulation, used during a web apps’ request cycle. In my app, I keep requests < 100ms.

I’d much rather write all new code in Elixir, but the only way I know to call it from Rails is as a web microservice.

(As I write this, I’m thinking about how ridic fast a stateless, logic-only Elixir web microservice can be: sub-millisecond. So I ought to have time to make a call to one during a Rails server’s response. And this might be my answer.)

Most Liked Responses

sribe

sribe

You could certainly skip HTTP, have Elixir just reading from Unix domain socket(s), commands in whatever stripped-down format you want to come up with, and the same for writing results back. (Communications over domain sockets is ridiculously fast.)

rjk

rjk

in this context it’s also good to be aware of something like terraform. The idea would be to put your elixir app before your rails app and per route decide if you handle it with elixir or with ruby. So your elixir app is acting like a reverse proxy in front of your rails app. In this way you can gradually migrate to elixir.

Unsure if there is any authentication or other context you need to handle for the incoming requests from elixir but i’ve done stuff like this by temporarily connecting to the same database as rails (read only) or making internal api routes to get context with from elixir to rails.

Another option is going with a persistent phoenix channel connection from ruby to the elixir app but this would introduce way more complexity (and needs clear interfaces on all sides). Then I would prefer the simplest solution of terraform: handle it with elixir first (via plain HTTP) or else fallback with rails (via plain HTTP).

sb8244

sb8244

Author of Real-Time Phoenix

Just a crazy thought. What if you ran the elixir application in the same OS as the rails app? Then you could make keep-alive requests from Ruby to elixir. It’s not going to be as fast as native Ruby, but it would be fine in a lot of cases.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

We're in Beta

About us Mission Statement