What is sparse fieldsets and response compression in REST API performance?

Answer

Sparse fieldsets let clients request only the fields they need, similar to GraphQL's field selection: GET /users?fields=id,name,email. This reduces payload size, database column fetching, and JSON serialization time. The JSON:API specification formalizes this with the fields[type] parameter. Response compression reduces bandwidth by compressing response bodies. The client sends Accept-Encoding: gzip, br and the server compresses the response body, returning Content-Encoding: gzip. Gzip provides ~70-90% size reduction for JSON. Brotli (br) achieves better compression ratios. Enable compression at the web server or API gateway level (Nginx, AWS CloudFront) so application code is not burdened. Together, sparse fieldsets and compression are especially impactful for mobile clients on metered connections where data transfer directly affects user cost.