'Calling Rust from Python: Shall I use shared library or sidecar pattern? [closed]

I maintain a big repo written in Rust, which involves certain functionalities such as I/O with databases, and communications with other nodes using Websocket.

Now I need to allow other people to write Python scripts which can use DB I/O and websocket stuff, which is written in Rust as mentioned above. Looks like I have 2 possible approaches:

  1. One way is to compile those Rust-written stuff into shared libraries (.so files on linux), and then load them as with Ctypes in Python.
  2. Another way is to build a "sidecar" written in Rust which has these DB and Websocket functionalities, run the sidecar as a daemon process and let the Python script interact with this daemon process with IPC (e.g., socket).

I feel there are pros / cons in each approach. For the first approach, dealing with either Rust ffi or Python Ctypes is probably not very straightforward. The second approach might have a little bit overhead in latency.

Nowadays I am seeing more and more adoption of the 2nd approach (a.k.a. sidecar pattern), while the 1st approach sounds more old-schooled. I want to post my question here, and would appreciate any comments regarding this!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source