Magento Redis cache compression is one of the smallest changes in Magento 2 performance optimization, yet on many stores it never actually runs. The installer writes a setting that looks like compression is active, while the library field stays empty. Every cache entry then travels to Redis uncompressed. For large catalogs, multiple store views, and traffic spikes, that gap wastes memory and network capacity.
Quick answer: Redis does not compress anything in Magento. PHP compresses cache entries before saving and decompresses them after reading. ZSTD at level 1 is a strong default, because in published tests it matched Gzip level 6 on size at a fraction of the write cost. It only works when the PHP extension exists in every runtime that touches the cache.
What Is Magento Redis Cache Compression?
Magento Redis cache compression shrinks serialized cache entries in PHP before they are stored in Redis or Valkey. Smaller entries use less Redis memory and put fewer bytes on the network.
Short answer: PHP does the compression work. Redis stores and returns the smaller values.
Who Does the Work, PHP or Redis?
The cache backend inside Magento checks the size of each value on save. Values above a set threshold are compressed. Smaller values are stored as they are, because the network round trip costs more than the bytes saved.
Redis shows no extra CPU load after compression is enabled. The cost lands on PHP workers, which matters when sizing servers.
Why Redis Cache Optimisation Matters for eCommerce
Cache performance sits at the center of a healthy ecommerce backend. Configuration data, translations, layout fragments, and attribute metadata are read on nearly every request. Each cache miss pushes work back to the database and PHP.
In the published production measurements, the largest entry (the admin configuration structure) was stored at 9.25 MB and took 65 to 70 ms per read. Reads of that size, multiplied across many PHP workers, can saturate a network link. The risk peaks right after a deployment or cache flush, when every worker rebuilds and re-reads the same entries.
Cloud networking adds pressure. Smaller instances and managed Redis nodes often get a baseline throughput plus a burst allowance. After the burst is spent, every call on the link slows down, including sessions, queues, and database traffic. Cross-zone traffic can also be billed, at $0.01 per GB in each direction on AWS in the referenced measurements.
Short answer: large cache entries drain memory and bandwidth. Compression reduces both.
Cache Efficiency in Platform Decisions
Cache design becomes a factor when choosing the right eCommerce platform 2026 teams can sustain. SaaS platforms such as Shopify and BigCommerce manage caching internally. WooCommerce usually depends on object cache plugins and hosting-level tuning. Magento and Adobe Commerce give engineering teams direct control over Redis, which brings flexibility and responsibility.
In a headless vs traditional commerce comparison, the storefront changes but the backend remains. In a headless eCommerce architecture, configuration, attribute metadata, and translations typically stay cache-heavy because Magento still serves API requests. Catalog updates, including output from AI product data enrichment workflows, trigger cache invalidation and regeneration. Efficient cache storage softens the cost of frequent updates.
Understanding Gzip, LZ4, and Zstandard (ZSTD)
Magento’s classic Redis backend supports five codecs: Gzip, LZF, LZ4, Snappy, and Zstandard. Gzip is always available through the PHP zlib extension. The other four need a separate PHP extension.
- Gzip is the long-standing default. The compression ratio is strong but write cost climbs at higher levels.
- LZ4 prioritizes speed. Compression and decompression are extremely fast, but entries stay larger. The codec is maintained in the LZ4 project repository.
- Zstandard (ZSTD) was created at Facebook (now Meta) to combine high ratios with high speed. The official Zstandard site documents the algorithm and its adjustable levels.
Snappy and LZF were not part of the benchmark, so no performance claims are made about them.
Short answer: Gzip compresses well but costs more CPU, LZ4 is fastest but leaves bigger entries, and ZSTD balances both.
ZSTD vs Gzip vs LZ4: Compression Performance Comparison
The figures below are measured results from a published benchmark on a production Magento 2.4.7 store. The test used the 40 largest default cache entries, totaling 16.2 MB. Timings are single-threaded totals on an arm64 laptop. The read estimates assume a 0.38 ms round trip and about 150 MB/s of effective throughput. Absolute numbers vary by hardware, so the order between codecs is the useful part.
- No compression: 16.2 MB stored, estimated read of all 40 entries about 124 ms.
- Gzip level 1: 4.1 MB (3.9x), compress 79 ms, decompress 14 ms, estimated read 98 ms.
- Gzip level 6: 3.6 MB (4.5x), compress 137 ms, decompress 11 ms, estimated read 81 ms.
- LZ4: 5.3 MB (3.1x), compress 5 ms, decompress 1 ms, estimated read 55 ms.
- ZSTD level 1: 3.7 MB (4.4x), compress 7 ms, decompress 5 ms, estimated read 58 ms.
- ZSTD level 3: 3.4 MB (4.8x), compress 8 ms, decompress 4 ms, estimated read 53 ms.
ZSTD level 1 compressed nearly as well as Gzip level 6 at about a twentieth of the write cost. LZ4 was cheapest on CPU but left the most bytes on the wire.

Not Every Cache Entry Compresses Equally
Results varied by entry type. The admin configuration structure (9.25 MB raw) compressed about 15x with ZSTD level 1. Layout and EAV attribute entries landed roughly between 8x and 15x depending on codec. Translations compressed around 3x.
The merged system configuration compressed only about 1.3x. System configuration entries are stored encrypted, and encrypted data does not compress. About a fifth of the measured set fell into that group.
Before and After on a Real Store
Moving the same store from no compression to ZSTD level 1 changed single-read wire times:
- Admin configuration structure: 9.25 MB and 67.6 ms before, 0.60 MB and 6.1 ms after.
- Translations: 0.67 MB and 4.4 ms before, 0.21 MB and 1.8 ms after.
- Merged system configuration: 1.70 MB and 15.2 ms before, 1.24 MB and 17.8 ms after.
Decompression adds a few milliseconds on the largest entry. Encrypted data can end up marginally slower, so gains should be expected mainly on large, repetitive entries.
How Magento Redis Cache Compression Works
Understanding the data path makes troubleshooting easier. In Magento 2.4.8 and earlier, the backend is Cm_Cache_Backend_Redis. On each save, the backend measures the serialized value. When the size reaches compress_threshold (20,480 bytes by default), PHP calls a function such as gzcompress() or zstd_compress(). The result is stored with a short prefix: gz:, zs:, l4:, sn:, or lz:. On load, the backend reads the prefix and calls the matching decompression function.
Two consequences follow:
- Every PHP runtime that reads the cache needs every codec used to write it. CLI and cron images count, not only PHP-FPM.
- A missing extension causes a fatal error such as
Call to undefined function zstd_compress(), not a silent fallback.
When compression_lib is absent from env.php, the backend picks the first available codec in this order: Snappy, LZ4, ZSTD, LZF, Gzip.
Short answer: Magento adds a prefix to each compressed value and reads it back to choose the right decompression function.
The Default That Quietly Disables Compression
The command bin/magento setup:config:set --cache-backend=redis writes 'compress_data' => '1' and 'compression_lib' => ''. It reads as “compression on, library automatic.” In practice, the empty string counts as a configured value, automatic selection is skipped, and the empty library name fails the check that guard’s compression. Every value goes to Redis raw. Any store set up with that command deserves an audit.
Magento 2.4.8 Redis Compression Configuration
Magento 2.4.8 and earlier use the classic backend. A working ZSTD setup in app/etc/env.php:
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
'backend_options' => [
'server' => 'redis',
'port' => '6379',
'database' => '0',
'compress_data' => '1',
'compress_threshold' => '20480',
'compression_lib' => 'zstd',
],
],
],
],
compress_datais the compression level passed to the codec. A value of0disables compression, and1is enough for ZSTD.compress_thresholdis measured in bytes. Below it, the round trip dominates and compression only adds CPU cost.compression_libacceptsgzip,lzf,l4z(the backend’s spelling of LZ4),snappy, andzstd. An empty string should never be used.
The same options apply under page_cache when Redis stores the full-page cache. Session storage is separate. The Redis session handler supports Gzip, LZF, LZ4, and Snappy, but not ZSTD.

Magento 2.4.9 Redis Compression Configuration
Magento 2.4.9 adds a cache layer built on symfony/cache. It activates when backend is the short name redis or valkey. A full class name such as Magento\Framework\Cache\Backend\Redis still routes through the older backend and its older options. On the new path, Magento compresses in its own decorator, and several option names change:
'backend' => 'redis',
'backend_options' => [
'server' => 'redis',
'port' => '6379',
'database' => '0',
'compress_data' => '1',
'compression_lib' => 'zstd',
'compression_level' => '1',
'compression_threshold' => '20480',
],
Differences from the classic backend:
compress_databecomes a plain on/off switch. Compression stays off when the key is absent.compression_levelis new, accepts 1 to 9, and defaults to 6. Setting it explicitly avoids running ZSTD at an unmeasured level.compression_thresholdreplacescompress_thresholdand defaults to 2,048 bytes.- An empty
compression_libnow means Gzip. - A missing extension no longer fails on write. The value is stored uncompressed and nothing is logged, so results must be verified.
Adobe Commerce on managed infrastructure needs one more check. In the Magento 2 vs Adobe Commerce Cloud question, Magento 2 Commerce Cloud projects generally control backend options through cloud configuration files, not hand-edited env.php. The Adobe Commerce Redis configuration guide lists supported settings.
Short answer: 2.4.8 uses compress_data as the level and compress_threshold. 2.4.9 on the short redis backend uses compression_level and compression_threshold.
How Compression Affects Memory, CPU, and Network Performance
Memory. The 40 largest entries shrank from 16.2 MB to 3.7 MB on an instance holding about 170 MB. About 97% of keys stayed under the 20 KB threshold, so compression does not halve a managed node. The benefit is strongest when an instance runs near maxmemory, or when a release writes a second generation of large entries under a new cache prefix.
CPU. Redis does no extra work (about 26 µs per HGET in the measurements). PHP pays the cost, mostly on writes. On the production pod, Gzip level 6 needed 113 ms to compress the admin configuration structure, while ZSTD level 1 ran above 4 GB/s in the benchmark. Writes cluster after deployments and cache flushes, which is the worst moment for a 100 ms save.
Network. At a 4.4x to 4.8x ratio, ZSTD puts less than a quarter of the raw bytes on the wire, against about a third for LZ4. On a congested link, ratio tends to matter more than decompression time. That explains why ZSTD level 3 beat LZ4 in the estimated read totals.
All results come from one store and one environment. Gains depend on entry sizes, worker counts, and network conditions, so testing on a staging copy is the safest path. Server response time also feeds into page speed metrics, covered in the web.dev guide to Time to First Byte.
Short answer: compression saves Redis memory and bandwidth, costs PHP CPU, and leaves Redis CPU unchanged.
Important Implementation Considerations
PHP Extensions in Every Runtime
The zstd extension must exist in PHP-FPM, CLI, and cron images. A deployment that installs it only on web containers breaks commands such as bin/magento cache:flush on the classic backend. On 2.4.9, the same gap silently produces uncompressed data. The community-maintained php-ext-zstd project provides the extension source.
Cache Verification
On the classic backend, the cache key follows the pattern zc:k: plus, the cache id_prefix plus the entry name. Two commands confirm the result:
redis-cli HSTRLEN "zc:k:<id_prefix>ADMINHTML__BACKEND_SYSTEM_CONFIGURATION_STRUCTURE" d
redis-cli HGET "zc:k:<id_prefix>ADMINHTML__BACKEND_SYSTEM_CONFIGURATION_STRUCTURE" d | head -c 3
The first returns stored size in bytes. The second prints zs: when ZSTD wrote the value. For caches outside database 0, add -n <database>. On 2.4.9 the key layout differs, so comparing cache database memory before and after a flush and warm-up is more reliable.
Rollback Planning
The extension and the env.php change should ship in the same release. An older image without the extension cannot read entries written with ZSTD. Two safe options exist: flush the cache during rollback or use a cache prefix per build so each image reads only its own entries.
Why Redis Sessions Need a Separate Instance
A separate database number is not enough. The maxmemory limit applies to the whole instance, and a cache instance is built to fill up and evict. Eviction can remove session data, which logs customers out and empties carts. Redis also runs commands on a single thread, so a multi-megabyte cache read can delay every session lock queued behind it. Sessions belong on a dedicated instance with the noeviction policy. The Redis eviction documentation explains how maxmemory policies behave. Valkey-based setups follow the same logic, as described on the Valkey project site.
Short answer: sessions and cache must not share an instance, because cache eviction can delete live sessions.
Best Practices for Magento Redis Cache Optimisation
Which compression method suits most stores? ZSTD at level 1 with a threshold near 20 KB is the strongest starting point based on the measured results. LZ4 suits environments where PHP CPU is the tightest resource and network capacity is generous. Gzip remains the fallback when installing extensions is not possible.
A practical checklist for ecommerce performance optimization at the cache layer:
- Audit
env.phpfor an emptycompression_libvalue. - Install the ZSTD extension across PHP-FPM, CLI, and cron before changing configuration.
- Set the compression level explicitly on Magento 2.4.9.
- Verify stored size and codec prefix after release.
- Keep sessions on a dedicated Redis instance with
noeviction. - Test on staging with production-sized cache data.
- Prepare a rollback path using cache flushes or per-build prefixes.
Cache tuning works best alongside broader platform work, such as query optimization, full-page cache strategy, and ecommerce API integration services that avoid unnecessary backend calls. Stores needing hands-on engineering support can draw on Magento enterprise development and Adobe Commerce development services. Teams planning a decoupled front end can review headless ecommerce development options, for example with the Adobe Commerce GraphQL documentation, while keeping the Magento backend cache healthy.
At Create & Commerce, Magento eCommerce development projects treat cache configuration as an architectural concern, not a post-launch afterthought. The Magento codebase itself is open for review in the official Magento 2 repository.

Frequently Asked Questions
What is Magento Redis cache compression?
It is the process of compressing cache entries in PHP before storing them in Redis or Valkey. Smaller entries reduce Redis memory use and network traffic.
Does Redis perform the compression?
No. PHP handles compression and decompression inside the Magento cache backend. Redis only stores and returns the smaller values.
Which is better for Magento: ZSTD, Gzip, or LZ4?
ZSTD at level 1 offers the best balance in the referenced benchmark. It matched Gzip level 6 on size at far lower write cost. LZ4 is lightest on CPU but leaves larger entries.
Does the Magento installer enable cache compression by default?
Not effectively. The setup command writes compress_data as 1 but leaves compression_lib empty. On the classic backend, that combination results in no compression.
What happens if the ZSTD extension is missing?
On Magento 2.4.8 and earlier, a missing extension causes a fatal error. On the new 2.4.9 cache path, values are stored uncompressed without any logged error.
Can Redis sessions and cache share one instance?
Sharing is not recommended. Cache instances evict data under maxmemory, which can remove sessions and log customers out. Sessions should run on a dedicated instance with noeviction.
Does the Magento Redis session handler support ZSTD?
No. The session handler supports Gzip, LZF, LZ4, and Snappy.
How can compression be verified after deployment?
Use redis-cli HSTRLEN to check stored size and HGET … | head -c 3 to see the codec prefix on the classic backend. On Magento 2.4.9, compare cache database memory before and after a flush and warm-up.
Is Magento Redis cache compression relevant for headless stores?
Yes. A headless storefront still depends on the Magento backend. Configuration, attribute metadata, and translation entries remain cache-heavy.
Conclusion
Magento Redis cache compression delivers measurable savings in memory and network load for a few lines of configuration, provided the setup is verified. ZSTD at level 1 stands out as the practical default, with LZ4 and Gzip as situational alternatives. Successful rollout depends on details: the PHP extension in every runtime, the right option names for Magento 2.4.8 versus 2.4.9, post-release verification, a rollback plan, and sessions kept on their own instance.
Create & Commerce helps merchants and technical teams review cache architecture, plan safe rollouts, and build scalable platforms across Magento, Adobe Commerce, and headless setups. A cache audit is a sensible first step for any store that has never confirmed whether compression is actually running.
