Skip to content

feat: compress API request bodies with zstd at level 1 - #35

Merged
metalwarrior665 merged 1 commit into
masterfrom
feat/zstd-request-compression
Nov 11, 2026
Merged

metalwarrior665 merged 1 commit into
masterfrom
feat/zstd-request-compression

Conversation

@metalwarrior665

Copy link
Copy Markdown
Member

This upgrades apify-client to 0.17.0, which adds ZstdHttpCompressor, and switches every API client of the SDK from brotli at quality 1 to zstd at level 1.

Why: on 2,000 real push bodies from the Instagram profile scraper (median 37 KB), zstd at level 1 takes 97 µs per body, against 242 µs for brotli at quality 1. Its output is also about 6% smaller (0.140 of the input against 0.149). Compression is about 9.6% of a profile run's CPU.

The API takes it. I checked this on the platform with client 0.17:

  • Dataset pushes, key-value records and request-queue batch adds sent with Content-Encoding: zstd all read back unchanged.
  • A record stored zstd-encoded is served decoded to readers that don't send Accept-Encoding: zstd, so the JS SDK, the Console and curl still get plain JSON.

Changes:

  • Config: Configuration::api_brotli_quality becomes api_zstd_level (1 to 19, default 1). An invalid level keeps the client's own compression (brotli), as before.
  • Breaking changes in the client:
    • ReqwestBackend now honours HttpRequest::follow_redirects through a second shared reqwest client that follows no redirects, as the client's own backend does.
    • The backend sends the new PATCH, OPTIONS and TRACE methods.
  • Tests: a push is checked to arrive zstd-encoded at the configured level and to decode to the items, a request with follow_redirects: false gets the 302, and the fake API of tests/storage.rs now decodes zstd bodies.
  • Docs: docs/allowed-differences.md is updated.

zstd compiles a C library (zstd-sys), so building the SDK now needs a C compiler. Rust's Docker images and the CI runners have one.


Generated by Claude Code

apify-client 0.17 adds ZstdHttpCompressor, and the Apify API now accepts
Content-Encoding: zstd: dataset pushes, key-value records and request
queue batch adds read back unchanged, and a record stored zstd-encoded is
served decoded to readers that don't accept zstd. On real push bodies zstd 1
is about 2.5x faster than brotli 1, for bodies about 6% smaller.

Configuration::api_brotli_quality becomes api_zstd_level (1 to 19,
default 1). The reqwest backend honours HttpRequest::follow_redirects
with a second client that follows none, and sends the new PATCH, OPTIONS
and TRACE methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
@metalwarrior665
metalwarrior665 merged commit efde377 into master Nov 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants