datalevin

Jeremy 2025-02-16T20:42:48.802969Z

Hi everyone, I'm hoping to use datalevin as the backend for durable event streaming. Is this possible? My use case peaks at around 5k msg/s. I was thinking of using a list-dbi, but the constraint of 512 bytes per event is tough

Huahai 2025-02-16T21:09:34.250939Z

Why would you want to use list dbi?

Huahai 2025-02-16T21:19:40.430349Z

Event streaming probably doesn’t need durability, so you can use non durable env flags, such as :nosync, writemap+mapasync, these can handle lots of loads

Huahai 2025-02-16T21:28:11.403809Z

you can also add :append flag when writing, so it's a bit more faster

πŸ‘ 1
Huahai 2025-02-16T21:37:41.197559Z

you can also use transact-kv-async if you care about durability, it can reach performance on par with those using non-durable flags, maybe slightly slower.

Jeremy 2025-02-17T01:03:00.375289Z

I considered list dbi cause I was looking for something that allows appending to the same key. If I were to :put data with :appenddup , how can I get back all associated values for a key?

Huahai 2025-02-17T01:04:04.194419Z

get-list

Huahai 2025-02-17T01:04:40.061129Z

I have not used :appenddup, don't know if it works

Huahai 2025-02-17T01:05:00.419789Z

why do you want to append to the same key?

Huahai 2025-02-17T01:05:54.735279Z

list dbi is limited, as the value has the same size limit as the key, so it's not really suitable for a lot of cases

Huahai 2025-02-17T01:06:59.844889Z

use tuples as keys is better

Jeremy 2025-02-17T01:08:22.911729Z

I see. I want to be able to quickly get all the events (about 200k) for a particular market that's why

Huahai 2025-02-17T01:09:18.852119Z

no difference

Huahai 2025-02-17T01:10:08.063749Z

use tuple as keys can do the same, and there's no limit on the value size

Huahai 2025-02-17T01:12:21.792449Z

or if you can use a separate table for the bigger values, like we do in Datalog store, it's a bit complicated, but it works

Jeremy 2025-02-17T01:18:32.124809Z

If I were to use tuples, What would be the right approach to getting all events for a market? Is it something like:

(d/get-range
 db "stream"
 [:closed ["producer-17-02-2025" "market-id"]])

Huahai 2025-02-17T01:19:45.847179Z

are these all strings?

Jeremy 2025-02-17T01:21:15.827989Z

yup. each event has an integer id too, but the range is unknown

Jeremy 2025-02-17T01:22:13.770929Z

ok, it seems add the int id with 0 and a huge number for the end-range does it

Huahai 2025-02-17T01:22:36.274139Z

since there's date in there, won't it be problematic when you try to do range on dates?

Jeremy 2025-02-17T01:24:52.353829Z

For this particular use case, I'm only every interested in all events so far for a market. the date is just part of the producer name which could be a uid in the future

Huahai 2025-02-17T01:26:13.427099Z

I would put a market-id at first position of tuple then

πŸ‘ 1
Huahai 2025-02-17T01:29:25.959279Z

(d/get-range db "stream" [:closed [["market-id-1" :db.value/sysMin] ["market-id-1" :db.value/sysMax]] [:string] :string)

Huahai 2025-02-17T01:29:33.090169Z

assuming your values are string

Jeremy 2025-02-17T01:30:07.512459Z

Lastly, regarding async transactions -> does calling sync finish up all async transactions too -> does awaiting the latest transact-kv-async guarantee that the previous calls are also done? (I assume they're batched up in order)

Huahai 2025-02-17T01:30:08.661519Z

so this is a homogeneous tuple

Huahai 2025-02-17T01:31:05.758059Z

no

Jeremy 2025-02-17T01:31:11.702619Z

> :db.value/sysMin great. I didn't know we could have that in a transaction

Jeremy 2025-02-17T01:32:27.056709Z

> no To both?

Huahai 2025-02-17T01:33:36.650769Z

first -> is no, sync does not interact with async transaction

Huahai 2025-02-17T01:34:01.278719Z

to do what you want to do, deref the last future

Huahai 2025-02-17T01:34:14.995019Z

so second -> is yes

πŸŽ‰ 1
Huahai 2025-02-17T01:35:26.949219Z

yes, they keeps the order, each async call is a future, you can deref the last one to make sure everyone is committed.

Huahai 2025-02-17T01:36:23.061219Z

or you can put in a callback for the last call

Jeremy 2025-02-17T01:38:00.901079Z

Awesome. Thanks for the help as always

Huahai 2025-02-17T01:39:43.029159Z

you are welcome