TExcelTAD
Home › AWS Cloud › Amazon Redshift

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

  1. Columnar storage: a query that sums amount reads only the amount column, not whole rows.
  2. Compression: values in one column are similar and compress very well.
  3. 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.
  4. 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

sql
-- 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:

python · try it yourself
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:

python · try it yourself
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

python · try it yourself
# 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?

  1. Thousands of small transactions per second
  2. Analytical queries over large datasets
  3. Storing user sessions
  4. Serving static files

Why does a column store read less data for SELECT SUM(amount) FROM sales?

  1. It caches every query
  2. It reads only the amount column instead of whole rows
  3. It skips the WHERE clause
  4. It uses smaller disks

Which service runs SQL directly over files in S3 without loading them into a cluster?

  1. Amazon RDS
  2. Amazon Athena
  3. Amazon ElastiCache
  4. AWS Glue DataBrew