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:
- One way is to compile those Rust-written stuff into shared libraries (
.so
files on linux), and then load them as withCtypes
in Python. - 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!