1

I have a node server that will serve more than 10,000 users at the same time with big data, I already tried lz-string https://www.npmjs.org/package/lz-string but it's not good module because it's blocking the node thread.

Please answer these questions:

  1. is it better to compress the data in server and then decompress in client instead of send plain/json data?

  2. what is the best and fastest way to compress/decompress the data?

1 Answer 1

3

If you are sending large chunks of text data over the internet using HTTP protocol, then there are already some technologies in place to help you.

One is called HTTP Compression. HTTP protocol specifications allow few compression algorithms to perform on data being sent, but that requires the server and client to be properly configured for compression. Standard Node.js server will not compress the data without modifying code.


For bare Node.js without any frameworks and 3rd party modules there is zlib module made specially for HTTP compression, both server and client.


Using Express? Then there is a compression middleware.


It might also be worth looking using nginx as a proxy server to your node.js applications. Then you can easily flip the switch ON for compression in nginx, without needing to do anything in your Node.js application at all:

server {
  gzip on;
  ...
}

It really depends on the stack you are using, but the idea is same: compress the HTTP stream itself, as it is supported by the protocol.

Sign up to request clarification or add additional context in comments.

2 Comments

That's for your detailed answer, what options avaiable for socket.io communications?
You might want to subscribe to this issue: github.com/Automattic/socket.io/issues/1148 (1.2 shall support compression). WebSocket supports already, but Socket.io only from 1.2 (as planned). Look into two answers on the similar question here: stackoverflow.com/questions/16569042/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.