redisjacksonobjectmapper

RedisJSON vs Jackson ObjectMapper


There are two ways to handle JSON in Redis:

  1. Use Jackson ObjectMapper to serialize the data before storing it in Redis, and then deserialize it when retrieving the data.

  2. Use the RedisJSON module to store and query JSON data directly, without the need for serialization and deserialization.


The difference between the two is that using the RedisJSON module allows processing to be handled on the Redis server, whereas using Jackson ObjectMapper requires the application to handle the processing.

Considering factors such as performance, load, and bottlenecks, I'm curious about which method is better suited for different scenarios.


Solution

  • A somewhat broad question, but let me try to give a very brief summary, focusing on the major difference. Depending on the use case - of course - these considerations might or might not be important.

    Implementations using a hash for backing

    Implementations using the RedisJSON module

    All of the latter would ultimately result in performance improvements as they would both decrease the amount of data sent over the wire, but also the need to parse the data in some cases. Consider incrementing a number stored in an array in both cases:

    Case 1 - the whole JSON text needs to be fetched (if it is larger than the array in question - including all irrelevant data); then the path would have to be applied to get to the array n question; then the value needs to be deserialized, so it is incremented; then data needs to be serialized back and returned to the server;

    Case 2 - a single command to the server indicating the path to the element to increment needs to be sent