zackattackz

zackattackz

DBConnection Implementation via HTTP

Hello!

I am currently working on an implementation of an Ecto Adapter for XTDB v2.x. 2.x is not a production-ready version, but I just wanted to try to make this project as a way to learn more about Elixir and XTDB as well.

So first of course I would need to create a DB driver for Elixir. XTDB has an HTTP API so I figured I will implement the driver using that as the protocol.

To create a driver, it seems standard that you should implement the DBConnection.Connection behavior. I just have a few struggles with this.

1.) From looking at other DBConnection implementations (MyXQL, Postgrex), they all seem to implement their database-specific protocols via TCP. Then DBConnection is somehow able to keep these TCP connections alive (via pinging?). My question is, how would one implement a DBConnection for an HTTP based protocol, specifically for the ping callback. To my understanding, HTTP is stateless, so I don’t think there is a realistic way to implement ping for this. Should I just leave it undefined and force :idle_interval = 0? Which brings me to my next question…
2.) Is there anything to be gained from implementing DBConnection for an HTTP based protocol? The main value-gain from implementing DBConnection seems to be that it is able to pool and maintain open TCP connections. I don’t know if there are other benefits, but if this is not applicable to HTTP, then should I bother with implementing it in the first place?

Sorry if these are ill-informed questions, as my knowledge of network protocols is very low. Any advice is appreciated, thank you!

Most Liked

al2o3cr

al2o3cr

There’s “keepalive” in HTTP/1.1 that lets a connection be used for multiple sequential requests.

You’d need to check if XTDB supports it, though.

The goal of connection pooling for this is largely around reducing the number of SSL handshakes required - every time a new connection is opened it takes a bunch of network round-trips and cryptographic calculations.

ruslandoga

ruslandoga

:wave: @zackattackz

I implemented an HTTP driver for ClickHouse and DBConnection was very useful.

  1. You can GET /status for handle_ping, it would probably be enough to keep the connection alive.

  2. In addition to pooling and keeping connections alive, DBConnection provides a way to make them re-connect with backoff in case things go bad.

Just make sure to use an HTTP client without a pool!

Where Next?

Popular in Questions Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

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
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement