Storing value as gzip compressed

Hi Couchbase team,

I’m very new with Couchbase, I would like to know is it possible to store value as compressed gzip String or byteArray…? Please let me know if you also have some concern about it…

Thank you very much…!!

Hi @aditputama ,

Transparent compression is built into Couchbase Enterprise Edition (See Compression | Couchbase Docs).

You could GZIP documents yourself and store them as binary documents, but those documents wouldn’t be compatible with Couchbase services that expect JSON; you wouldn’t be able to do subdocument operations or N1QL queries, for example.

Thanks,
David

Hi @david.nault ,
Thank you very much for your response :slight_smile:

Now actually Im considering 2 options for compressing data from client side, whether using gzip or Snappy;
If I use gzip and enable compression on the server (compression mode : Active), will that binary value again be compressed using Snappy when it reach the server…?
And if I use Snappy, will the server automatically detect that it’s in Snappy-compressed form so that it will no longer perform compression on server side…?

Thank you for your support.

If I use gzip and enable compression on the server (compression mode : Active), will that binary value again be compressed using Snappy when it reach the server…?

Yes, with active compression the server will try to recompress it again. However, the server will probably discard the doubly-compressed result because it’s unlikely to meet the Compression Ratio threshold; this would just waste CPU cycles on the server.

And if I use Snappy, will the server automatically detect that it’s in Snappy-compressed form so that it will no longer perform compression on server side…?

No, the server will not detect it.

Thanks,
David

Hi @aditputama,

May I ask why you don’t want to let Couchbase Server and the SDK handle compression for you transparently?

Thanks,
David

Hi @david.nault ,

Actually I’m working with a migration project where the current app will compress it as gzip before keep it in the storage, and I was considering to do the same thing before I’m aware of Couchbase compression feature.

And yes, now I want to let Couchbase Server and the SDK to handle it for me.

Regarding compression from SDK, do we simply have to set this config and let the magic happen…?
https://docs.couchbase.com/java-sdk/current/concept-docs/compression.html#minimum-size
Actually I’m struggling to find more information for client side (I’m using JAVA SDK) compression but can’t find any so far…

Suppose if we compress it with snappy from the SDK, would we still be able to perform subquery or even see the data value from UI dashboard as JSON ?

Thank you for your support,
Aditya

Hi Aditya,

The compression config options for the Java SDK are documented here: Client Settings | Couchbase Docs

Compression is enabled by default. You can tune the other settings if you want, but it’s not required.

Yes, that’s right.

Thanks,
David

1 Like