Amazon Redshift
Amazon Redshift is AWS's data warehouse: a database built for analytics on large amounts of data (gigabytes to petabytes) with SQL. Where RDS is tuned for many small transactions (OLTP: "insert this order"), Redshift is tuned for big queries over many rows (OLAP: "revenue per region per month for the last three years").
OLTP vs OLAP
| OLTP (RDS, Aurora, DynamoDB) | OLAP (Redshift) | |
|---|---|---|
| Typical query | Read/write a few rows by key | Aggregate millions of rows |
| Users | The application | Analysts, BI dashboards |
| Storage layout | Row-oriented | Column-oriented |
| Data freshness | Live | Loaded in batches or near-real-time |
How Redshift is fast
- Columnar storage: a query that sums
amountreads only theamountcolumn, not whole rows. - Compression: values in one column are similar and compress very well.
- Massively parallel processing (MPP): data is split across nodes (and slices); each works on its part in parallel, and a leader node combines the results.
- Zone maps: per-block min/max values let Redshift skip blocks that can't match a filter.
Redshift comes as provisioned clusters (you choose node types such as RA3) or Redshift Serverless (pay for compute used, measured in RPU-hours). Redshift Spectrum queries files in S3 directly, and Amazon Athena is a separate serverless service for SQL over S3.
Loading and querying
-- Load Parquet files from S3 into a table
COPY sales
FROM 's3://tad-datalake/sales/2026/'
IAM_ROLE 'arn:aws:iam::123456789012:role/redshift-s3-read'
FORMAT AS PARQUET;
SELECT region, DATE_TRUNC('month', sold_at) AS month, SUM(amount) AS revenue
FROM sales
GROUP BY 1, 2
ORDER BY 1, 2;Model: row store vs column store
How many bytes must be read to compute SUM(amount)? A row store reads entire rows; a column store reads one column:
columns = {"order_id": 8, "customer": 40, "region": 12, "product": 60, "amount": 8, "sold_at": 8}
rows = 50_000_000
row_bytes = rows * sum(columns.values())
column_bytes = rows * columns["amount"]
def gb(n):
return n / 1e9
print(f"row size: {sum(columns.values())} bytes")
print(f"row store reads : {gb(row_bytes):6.2f} GB")
print(f"column store reads: {gb(column_bytes):6.2f} GB ({row_bytes // column_bytes}x less)")
compression = 4 # example: numbers in one column often compress ~4x or better
print(f"compressed column : {gb(column_bytes / compression):6.2f} GB")row size: 136 bytes
row store reads : 6.80 GB
column store reads: 0.40 GB (17x less)
compressed column : 0.10 GB
Model: MPP aggregation
Each node computes a partial result for its share of rows; the leader merges them. The answer is identical to a single-machine computation:
from collections import defaultdict
sales = [("EU", 120), ("US", 300), ("EU", 80), ("APAC", 50), ("US", 70),
("EU", 40), ("APAC", 90), ("US", 30), ("EU", 60)]
NODES = 3
slices = [sales[i::NODES] for i in range(NODES)] # round-robin distribution
partials = []
for n, chunk in enumerate(slices):
part = defaultdict(int)
for region, amount in chunk:
part[region] += amount
partials.append(dict(part))
print(f"node {n}: {len(chunk)} rows -> {dict(sorted(part.items()))}")
final = defaultdict(int)
for part in partials:
for region, total in part.items():
final[region] += total
print("leader merges:", dict(sorted(final.items())))
single = defaultdict(int)
for region, amount in sales:
single[region] += amount
print("same as single machine:", dict(final) == dict(single))node 0: 3 rows -> {'APAC': 140, 'EU': 120}
node 1: 3 rows -> {'US': 400}
node 2: 3 rows -> {'EU': 180}
leader merges: {'APAC': 140, 'EU': 300, 'US': 400}
same as single machine: True
With N nodes, each scans about 1/N of the data, so adding nodes makes big scans faster. Redshift's distribution style (KEY, EVEN, ALL, AUTO) controls how rows are placed; distributing two large tables on the same join key avoids moving data between nodes during joins.
Model: zone maps skip blocks
# Rows sorted by sold_at (the SORTKEY), stored in blocks of 4 rows; each block keeps (min, max)
dates = ["2026-01-03", "2026-01-09", "2026-01-15", "2026-01-28",
"2026-02-02", "2026-02-11", "2026-02-19", "2026-02-27",
"2026-03-01", "2026-03-04", "2026-03-12", "2026-03-30"]
blocks = [dates[i:i + 4] for i in range(0, len(dates), 4)]
zone_map = [(b[0], b[-1]) for b in blocks]
lo, hi = "2026-02-10", "2026-02-20" # WHERE sold_at BETWEEN lo AND hi
read = [i for i, (mn, mx) in enumerate(zone_map) if not (mx < lo or mn > hi)]
print("zone map:", zone_map)
print("blocks read:", read, f"({len(read)} of {len(blocks)})")
print("matching rows:", [d for i in read for d in blocks[i] if lo <= d <= hi])zone map: [('2026-01-03', '2026-01-28'), ('2026-02-02', '2026-02-27'), ('2026-03-01', '2026-03-30')]
blocks read: [1] (1 of 3)
matching rows: ['2026-02-11', '2026-02-19']
Zone maps work best when the table is sorted by the column you filter on, which is why choosing a sort key (often a date) matters.
Test yourself
Which workload is Redshift designed for?
- Thousands of small transactions per second
- Analytical queries over large datasets
- Storing user sessions
- Serving static files
Why does a column store read less data for SELECT SUM(amount) FROM sales?
- It caches every query
- It reads only the
amountcolumn instead of whole rows - It skips the WHERE clause
- It uses smaller disks
Which service runs SQL directly over files in S3 without loading them into a cluster?
- Amazon RDS
- Amazon Athena
- Amazon ElastiCache
- AWS Glue DataBrew