CLOUD CONCEPT

Data Compression

Data compression represents information using fewer bytes to reduce storage consumption and data movement.

Cloud Concepts Hub →

What is Data Compression

Compression reduces the physical size of data by encoding it more efficiently, usually without losing information in engineering and analytics workloads. In cloud architectures, it can lower storage and query costs and improve transfer throughput, but it introduces processing overhead and must match the workload's access patterns.

Data compression reduces the number of bytes needed to represent information. Lossless compression preserves the original data exactly and is the normal choice for database records, logs, financial transactions, and analytical datasets. Lossy compression discards some information and is appropriate only when the application tolerates that loss, such as certain image, audio, or video workloads. Compression effectiveness depends on the data: repetitive text often compresses well, while encrypted data and already compressed media usually provide little additional reduction.

In cloud pipelines, compression can happen before upload, during transformation, or inside a storage engine. Compressing source files before transfer reduces the bytes crossing the network, which can shorten uploads when bandwidth is the bottleneck. However, it does not automatically reduce every bill. Internet data transfer into Amazon S3 is generally free, so compression primarily saves upload time and stored bytes in that case; source-provider egress charges, connectivity charges, and compression compute costs must also be considered. Compare the total cost of transferring the compressed dataset within the required deadline, rather than assuming that the smallest file always produces the cheapest migration.

File format and compression are separate choices. CSV is a text-based row format, while Apache Parquet is a typed columnar format that supports encodings and compression codecs. Converting CSV to Parquet requires parsing records and assigning appropriate types; simply renaming a file does not transform it. For example, a pipeline can read sales CSV files, validate decimal amounts and timestamps, and write Parquet using Snappy or Zstandard where supported. Columnar layout lets an analytical engine read selected columns, while compression reduces the bytes needed for those columns. Format conversion can change textual representations, so preserve original files when byte-for-byte source fidelity is required.

Choose codecs using representative benchmarks. Snappy commonly favors compression and decompression speed, while Zstandard can provide stronger compression with configurable processing trade-offs. Gzip is widely compatible, but a conventional gzip-compressed CSV file is generally not splittable across workers within that file. A single very large gzip file can therefore limit parallel processing. Parquet with internal compression retains row-group-based parallel read opportunities; wrapping an entire Parquet file in an external gzip stream is generally unsuitable for analytical access.

Compression complements partitioning, indexing, and file sizing rather than replacing them. Partitioning by a frequently filtered date can eliminate irrelevant files, indexes or column statistics can help skip irrelevant data, and compression reduces the remaining bytes read. Excessive partitioning can create many small files. Compacting small records into appropriately sized files reduces object request overhead and improves processing efficiency, but compaction and compression are different operations. Combining records into fewer S3 objects can reduce PUT request counts; compressing each record separately does not. Multipart upload divides one object into upload parts and is not a way to combine many records into fewer objects or inherently lower request costs.

Balance batch size against ingestion latency, retry cost, and available parallelism. An hourly batch may be economical for reporting but unsuitable for alerts that require data within seconds. Measure stored size, upload duration, decompression CPU, query scan volume, and end-to-end latency. Confirm that every producer and consumer supports the selected format and codec, and compress before encryption when the application controls both operations. Compression is not encryption and provides no confidentiality by itself.

Key aspects of Data Compression

Effective compression preserves required information while balancing byte reduction, processing overhead, compatibility, parallel access, and total workload cost.

Lossless preservation

Use lossless compression when records must be reconstructed exactly. Treat lossy compression as an explicit application-level decision, not a routine optimization for analytical records.

Codec and compute trade-offs

Compression ratio, encoding speed, decompression speed, and memory consumption vary by codec and dataset. Benchmark realistic data and include compute costs rather than optimizing only for the smallest output.

Format-aware optimization

Columnar formats such as Parquet combine typed storage and column encodings with optional compression. Converting CSV to compressed Parquet can reduce both stored bytes and the amount of data analytical queries need to read.

Parallel access and splittability

Compression boundaries affect whether multiple workers can process a file concurrently. Prefer layouts with independently readable units for distributed analytics, and avoid a single large, nonsplittable compressed text file when parallelism matters.

Complementary data layout

Combine compression with selective partitioning, useful indexes or statistics, and suitable file sizes. These techniques reduce different sources of waste and should be evaluated together.

End-to-end cost evaluation

Account for storage, requests, network pricing, transformation compute, and latency. Batching records into fewer objects reduces request overhead, while compression reduces bytes; neither guarantees the lowest total cost independently.

Cloud services for Data Compression

AWS Glue can transform raw files into typed, compressed Parquet stored in Amazon S3. Amazon Data Firehose provides a streaming ingestion path that buffers records and can produce supported compressed or columnar output. Amazon Athena queries these S3 datasets directly, benefiting from compression, column selection, and partition pruning. Amazon Redshift applies its own column encodings when data is loaded into warehouse tables. Across these paths, choose compatible codecs and practical file sizes, and measure ingestion latency, transformation compute, storage consumption, and query costs together. S3 preserves the object bytes supplied by the producer; it does not perform the compression itself.

AWS Glue image AWS Glue

AWS Glue ETL jobs can parse CSV data and write compressed Parquet, with explicit schema and codec choices. Jobs can also reorganize data into partitions and compact small files to improve downstream query efficiency.

Open AWS Glue →
Amazon Simple Storage Service image Amazon S3

Amazon S3 stores compressed objects but does not automatically compress uploaded application data. Compress before upload or write compressed output from a processing pipeline, and evaluate object sizes, request counts, and storage-class billing rules.

Open Amazon S3 →
Amazon Athena image Amazon Athena

Amazon Athena can query supported compressed files and columnar formats in S3. For queries billed by data scanned, compressed Parquet combined with column selection and partition pruning can reduce scan charges compared with scanning uncompressed CSV.

Open Amazon Athena →
Amazon Redshift image Amazon Redshift

Amazon Redshift uses column compression encodings to reduce storage and I/O, with automatic encoding management available through ENCODE AUTO. Table compression is separate from the compression of source files used during loading.

Open Amazon Redshift →