Which clustered NoSQL DB for a Message Storing purpose?

后端 未结 3 981
长发绾君心
长发绾君心 2020-12-15 13:03

Yet another question about which NoSQL to choose. However, I haven\'t found yet someone asking for this type of purpose, message storing...

I have an Erlang Chat Ser

3条回答
  •  别那么骄傲
    2020-12-15 13:16

    I'd recommend using distributed key/value store like Riak or Couchbase and keep the whole message log for each user serialized (into binary erlang terms or JSON/BSON) as one value.

    So with your usecases it will look like:

    • Store from 1 to X messages per registered user - when user comes online spawn a stateful gen_server, which gets from storage and deserializes whole message log on startup, receives new messages, appends them to it's copy of log, on end of session it terminates, serializes the changed log and sends it to storage.
    • Get the number of stored messages per user - get the log out, deserialize, count; or maybe store count alongside in a separate k/v pair.
    • retrieve all messages from an user at once - just pull it from storage.
    • delete all messages from an user at once - just delete value from storage.
    • delete all messages that are older than X months - get, filter, put back.

    The obvious limitation - message log has to fit in memory.

    If you decide to store each message individually it will require from distributed database to sort them after retrieval if you want them to be in time-order, so it will hardly help to handle larger-than-memory datasets. If it is required - you will anyway end up with some more tricky scheme.

提交回复
热议问题