Sub topic 3
Compression and Smaller Payloads
Assume you know AWS regions, Availability Zones (AZs), VPCs, routing, and basic Cost Explorer use. This chapter focuses on reducing bytes before choosing a network path.
Compress payloads before they leave AWS
A payload is the data transferred by an application. Compressing it reduces the number of bytes sent over the network. JSON, HTML, text, and logs usually compress well. Images, videos, and ZIP files often do not.
Use gzip or Brotli for HTTP responses, and enable compression at the application or load-balancer layer. Remove unused fields, paginate large responses, and avoid sending the same data repeatedly.
import gzip
payload = b'{"status":"ok","message":"This text repeats. " * 100}'
compressed = gzip.compress(payload, compresslevel=6)
print(f"original: {len(payload)} bytes")
print(f"compressed: {len(compressed)} bytes")Cross-region traffic and replication
Cross-region transfers can incur charges in both the source and destination path, depending on the service. Avoid moving large datasets between regions unless replication or disaster recovery requires it. Place compute near its data, replicate only required tables or objects, and use incremental replication instead of full copies.
Peering and Transit Gateway trade-offs
VPC peering provides direct private connectivity between VPCs. It can be inexpensive for a small number of connections, but many peerings create routing complexity. Transit Gateway centralizes connectivity and routing. It is easier to govern at scale, but adds attachment and data-processing charges.
| Option | Best fit | Main cost concern |
|---|---|---|
| VPC peering | Few VPCs with direct traffic | Many connections become difficult to manage |
| Transit Gateway | Many VPCs and centralized routing | Per-attachment and per-GB processing |
Hybrid traffic
VPN uses encrypted tunnels over the internet and is quick to deploy. Direct Connect provides a dedicated connection with more predictable performance, but requires location, port, and recurring service planning. Compare those fixed costs with the volume and consistency of hybrid traffic.
Governance and an optimization workflow
Tag workloads and owners, then create budgets for data transfer and NAT gateway usage. Use Cost Anomaly Detection to alert on unusual spend. Review Cost Explorer by usage type, then use VPC Flow Logs to find high-volume source and destination pairs.
Apply this loop:
- Identify the largest transfer category and talker.
- Confirm the traffic path and business requirement.
- Reduce payload size or change placement and routing.
- Measure cost and performance after the change.
- Add a budget or alert to prevent regression.
Exercise
A service sends large JSON responses across regions. Name two changes that can reduce transfer cost.
Show answer
Compress the responses and send only required fields. Also place the service near its data or replace full cross-region copies with incremental replication.