2
rocktim
4y

Do we need compression on api level? say I have a rest api sending json data on requests. So if compression is needed then should it be in the server when returning the json response or in the client side when receiving it? which one is ideal?

Comments
  • 4
    What would be the benefit of client compressing the data? It would have to decompress it to use it anyway.
  • 1
    Server side compress, client side decompress - as it should be.
  • 2
    Won't gzip be enough? Most clients automatically handle that right?
  • 1
    @C0D4 Does the client automatically decompresses returned json ?? (ps: im new to this topic,just curious)
  • 1
    @unicorndev as @alexbrooklyn said, use gzip or BR, almost any modern client will decompress on its own without your interference.
  • 1
    @C0D4 ah i see. Thanks for the clarity on this topic guys 🦄
  • 1
    @unicorndev as for the original question, do you need to?

    If your hosting in cloud host (azure/aws), it would probably reduce your bill in the long run as you are sending less data, but if data isn't an issue... it falls under the "it's debatable", no harm in doing it even if you don't need to.
  • 1
    @C0D4 ah okey. And what about the speed. Doesn't compressing improve the overall speed of the api server when a client requests data?
  • 1
    @unicorndev that's really dependant in the amount of data your throwing back, if your sending thousands of records back in a single call... sure it would help.

    But the process behind the api would be the likely cause of a bottle neck to be concerned with or querying a database of some kind to retrieve the data in the first place.

    The transmission it's self is just a single not so controllable stage of the process. Fetching and modelling the data quickly is going to be the beneficial part to optimise well. Just compress and send and let the client chock on it or request smaller payloads - granted you added pagination of some kind.
  • 2
    @C0D4 I see.Thanks again for the explanation.I was going to ask this in StackOverflow. I am glad I didn't lol. This is much better. love this 🌸
  • 2
    @unicorndev one major difference in SO is that they generally frown upon discussions, answers should be answers which often cause down votes.

    But SO had one major feature, searchable.

    Answers here are much harder to find for others with the same question.
  • 0
    @Voxera Yes agreed. But It doesn't need to be SO. If you need any help finding a solution for an issue or how to work on something then google and SO is obviously there. But if you are curious about a topic and want to know a bit more about something then asking here is fine i guess. since most of the answers will be short and on point 🤗
  • 1
    @unicorndev sure :)
Add Comment