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

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.

hauleth

hauleth

Known as C Nodes (despotę the name, these do not need to be written in C).

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement