VAYULearn
Colour theme
Investigate a failure
VAYU Learn

AWS Data Engineering

Amazon Redshift: The Warehouse That Data Engineers Actually Operate

DataForge AWS Data Engineering Series - Blog 6 of 20

AWS Data EngineeringSQL & Databases

The dashboard query took 45 seconds. It used to take 2.

Nothing about the query had changed. The table had grown from 50 million rows to 400 million rows over six months — normal growth for an events table. The data engineer checked indexes, which don’t exist in Redshift the way they do in traditional databases. Checked cluster CPU, which was fine. The actual cause: the table’s distribution key was the row’s primary key, a high-cardinality column with no relationship to how the query joined or filtered data. Every query that joined this table to another required Redshift to shuffle data across every node in the cluster — a cost that scaled linearly with table size and had been quietly growing for six months until it crossed the threshold where users started noticing.

The fix required rebuilding the table with a different distribution key — a decision that should have been made on day one, when the table had 10,000 rows and any distribution key looked equally fast.

This is the defining characteristic of Redshift performance: the decisions that matter most are made once, at table creation, when there’s no data yet to reveal whether they’re right. Get them wrong, and the table works fine until it doesn’t — and by the time it doesn’t, fixing it means a full table rebuild, not a configuration tweak.

Let’s go deep.


TL;DR

Redshift is a columnar, massively parallel processing (MPP) data warehouse where query performance is determined almost entirely by two decisions made at table creation: the distribution key (how rows are spread across compute nodes) and the sort key (how rows are ordered within each node’s storage). Getting these wrong doesn’t cause errors — it causes queries that work correctly but slowly, with the slowness scaling as data grows, invisible until someone notices performance has degraded from what it used to be.

By the end of this article you’ll be able to:

  • Choose the correct distribution style for a given table and access pattern
  • Choose the correct sort key strategy and understand how it interacts with query filters
  • Explain why VACUUM and ANALYZE are operational requirements, not optional maintenance
  • Understand when Redshift Spectrum bridges the warehouse to the data lake, and when it doesn’t help

Series context: This builds directly on Blog 2 (S3 file layout determines COPY command performance) and complements Blog 5 (Glue jobs frequently write the data Redshift loads). Blog 7 will cover exactly when Redshift is the correct choice versus Athena.

Same join, same data, two distribution strategies. EVEN distribution shuffles the entire table across the network on every query. KEY distribution on the join column eliminates the shuffle entirely — co-located rows join locally, for free.

What Makes Redshift Different From a Regular Database

Redshift looks like PostgreSQL from the SQL interface — it’s actually based on a PostgreSQL fork — but the underlying execution model is fundamentally different, and that difference is the entire reason performance tuning works the way it does.

Traditional row-based database (PostgreSQL, MySQL):
Data stored row by row
A query selecting 3 columns out of 40 still reads
every column's data for each matching row
Good for: transactional workloads, frequent small
updates, row-level operations
Redshift (columnar, MPP):
Data stored column by column, compressed
A query selecting 3 columns out of 40 reads only
those 3 columns' data blocks
Data is distributed across multiple compute nodes
Queries execute in parallel across all nodes,
then results are combined
Good for: analytical queries, aggregations over
large datasets, infrequent bulk updates

The architectural consequence that drives everything else in this article: because data is distributed across nodes, a query that needs to combine data from different nodes (a join, a groupBy) requires moving data across the network between nodes. How much data needs to move — and therefore how fast the query runs — is determined entirely by how the data was distributed across nodes in the first place. That distribution decision is the distribution key, chosen once, at table creation.


Distribution Keys: The Decision That Determines Join Performance

The distribution key determines which node each row lives on. Get it right, and joins execute locally on each node with no data movement. Get it wrong, and every join requires shuffling data across the network — the Redshift equivalent of the shuffle costs covered extensively in the Databricks series.

Four distribution styles:
KEY distribution:
Rows distributed based on the hash of a specified column
Rows with the same key value land on the same node
Correct when: two large tables are frequently joined
on the same column
ALL distribution:
Full copy of the table replicated to every node
No network shuffle needed for joins involving this table
Correct when: small, relatively static dimension tables
(a few thousand to low millions of rows)
EVEN distribution:
Rows distributed round-robin, no relationship to any
column's value
Correct when: no clear join pattern exists, or the
table is rarely joined at all
AUTO distribution (Redshift's default recommendation):
Redshift chooses ALL for small tables, EVEN for larger
tables without a clear key candidate, and lets you
override with KEY when you know the join pattern

How Distribution Key Choice Actually Affects a Join: The Mechanism

This is the mechanism worth internalizing precisely — because once you see what happens physically during a join, the reason behind every distribution key recommendation becomes obvious.

Scenario: joining a 400M-row orders table to a
50M-row customers table on customer_id
Case 1: Both tables distributed EVENLY (no shared key)
orders table: 400M rows spread round-robin across
8 nodes = 50M rows per node, random
customers table: 50M rows spread round-robin across
8 nodes = 6.25M rows per node, random
To join on customer_id, Redshift must ensure matching
rows are on the same node. Since distribution was random,
NONE of the matching rows are guaranteed to be co-located.
Redshift's only option: broadcast or redistribute data
across the network so matching customer_id values land
on the same node before the join can execute locally.
This redistribution step moves potentially the ENTIRE
400M-row table across the network - for every query
that runs this join.
Case 2: Both tables distributed by KEY on customer_id
orders table: distributed by hash(customer_id) -
all rows for customer X land on node 3
customers table: distributed by hash(customer_id) -
customer X's row also lands on node 3
Every matching pair is already on the SAME node.
The join executes locally, node by node, with
ZERO network data movement.
Query time: bound by local processing speed, not
network shuffle time.

The distribution key decision, stated as a rule: identify the column that the largest, most frequent joins use to connect your biggest tables. Distribute those tables by that column. Every other table either gets ALL (if small and relatively static) or EVEN (if no dominant join pattern exists).


Sort Keys: The Decision That Determines Filter and Range Performance

Where the distribution key determines which node a row lives on, the sort key determines the physical order rows are stored in within each node’s disk blocks. This is what enables Redshift to skip reading blocks that can’t contain matching data — the same block-skipping concept as Parquet’s columnar statistics in Blog 2, applied within Redshift’s own storage.

Without a sort key (or a poorly chosen one):
Rows for 2024-01-15 could be scattered across every
disk block in the table
A query filtering WHERE event_date = '2024-01-15'
must scan every block to find matching rows
With event_date as the sort key:
Rows are physically stored in date order
Each disk block's metadata records the min/max date
it contains
A query filtering WHERE event_date = '2024-01-15'
skips every block whose min/max range doesn't include
that date - often skipping 95%+ of the table

Two sort key types:

Compound sort key (most common):
Columns sorted in priority order: (event_date, region)
Most effective when queries filter on the FIRST column,
or on the first column plus additional columns in order
Less effective if queries filter only on the SECOND
column without the first
Interleaved sort key:
Gives equal weight to multiple columns
Effective when queries filter on DIFFERENT columns
unpredictably (sometimes date, sometimes region,
sometimes customer_id)
Higher maintenance cost - VACUUM REINDEX is required
periodically and is expensive

The practical rule: compound sort keys on the column(s) that appear in WHERE clauses most consistently across your actual query patterns — usually a date or timestamp column for time-series data. Interleaved sort keys are correct only when query patterns are genuinely unpredictable across multiple columns, which is less common than teams initially assume, and the maintenance cost usually isn’t worth it unless that unpredictability is real and measured, not assumed.


The COPY Command: Where Blog 2’s S3 Decisions Pay Off or Cost You

COPY is how data enters Redshift from S3 in bulk, and its performance is a direct function of the file layout decisions covered in Blog 2.

COPY events
FROM 's3://bucket/silver/events/year=2024/month=01/day=15/'
IAM_ROLE 'arn:aws:iam::123456789:role/redshift-copy-role'
FORMAT AS PARQUET;

Why file count and size directly determine COPY speed:

Redshift's COPY command parallelizes across the cluster's
slices (each node has multiple slices - the internal unit
of parallelism)
Optimal: file count is a multiple of the number of slices
in the cluster, with each file roughly equal size
(100MB-1GB range works well for Parquet)
Sub-optimal: one giant file
Only ONE slice can process it - every other slice sits
idle while that one slice churns through the entire file
Sub-optimal: thousands of tiny files
Overhead per file (opening, reading metadata, closing)
dominates over actual data processing time - the same
small-file tax covered in Blog 2, now inside Redshift's
load process instead of Athena's scan process

The direct connection to Blog 2: if your Glue job (Blog 5) writes well-partitioned, appropriately-sized Parquet files to S3 Silver, your Redshift COPY command inherits that efficiency automatically. If your Glue job writes either one enormous file or thousands of tiny ones, Redshift’s load time suffers for exactly the same structural reason Athena’s query cost suffers — the file layout decision was made once, upstream, and every downstream consumer pays for it.


VACUUM and ANALYZE: Maintenance That Isn’t Optional

Unlike S3 (Blog 2), which requires no maintenance for correctness, Redshift tables actively degrade without regular maintenance — and the degradation is invisible until it isn’t.

Why VACUUM is necessary:
UPDATE and DELETE operations in Redshift don't
immediately reclaim space - they mark rows as
deleted and leave them in place
Over time, "deleted" rows accumulate, consuming
disk space and forcing queries to scan past rows
that no longer logically exist
VACUUM DELETE ONLY events;    -- reclaims space from
-- deleted rows
VACUUM SORT ONLY events; -- re-sorts rows to
-- match the sort key
-- (degrades as new data
-- is appended out of order)
VACUUM FULL events; -- both operations combined,
-- most expensive
Why ANALYZE is necessary:
Redshift's query planner makes execution decisions
based on table statistics (row counts, distinct value
estimates, etc.)
Stale statistics - the same problem covered in the
Databricks series' broadcast join discussion - cause
the planner to make wrong choices about join order,
join strategy, and resource allocation
ANALYZE events;

The maintenance schedule most production Redshift clusters need and most teams skip: VACUUM and ANALYZE aren’t one-time setup tasks — they’re ongoing operational requirements tied to write frequency. A table receiving continuous inserts and occasional updates needs both running on a recurring schedule (daily or after significant load volumes), not as a reactive fix once queries have already slowed down.

Automated approach (Redshift's newer versions):
Auto VACUUM and Auto ANALYZE run automatically in
the background during low-activity periods
Manual approach (still common, more control):
Scheduled via Lambda + EventBridge, or via a
Step Functions workflow (Blog 11) running after
each significant COPY operation

Redshift Spectrum: Bridging the Warehouse and the Data Lake

Spectrum lets Redshift query data directly in S3, without loading it into the cluster first — the same underlying mechanism as Athena (Blog 12), accessed through Redshift’s SQL interface.

CREATE EXTERNAL SCHEMA spectrum_schema
FROM DATA CATALOG
DATABASE 'raw_db'
IAM_ROLE 'arn:aws:iam::123456789:role/spectrum-role';

SELECT r.customer_name, s.total_revenue
FROM customers r -- lives in Redshift cluster storage
JOIN spectrum_schema.historical_orders s -- lives in S3,
-- queried via
-- Spectrum
ON r.customer_id = s.customer_id
WHERE s.order_date >= '2020-01-01';

When Spectrum is the right tool: historical data that’s too large or too cold to justify loading into the cluster’s limited storage, but occasionally needs to be joined with current warehouse data for specific analyses. Spectrum queries are billed like Athena — per TB scanned — so the same partitioning and Parquet format principles from Blog 2 apply directly to Spectrum performance and cost.

When Spectrum doesn’t help: if a query pattern is frequent and performance-critical, Spectrum’s per-query S3 scan cost and latency will consistently underperform data that’s actually loaded into the cluster with proper distribution and sort keys. Spectrum is a bridge for occasional access to cold data, not a substitute for loading frequently-queried data into the warehouse proper.


Workload Management (WLM): Handling Concurrent Queries

Redshift clusters serve multiple users and multiple query types simultaneously — dashboards, ad hoc analyst queries, scheduled ETL loads. Without configuration, a single expensive query can starve every other query of resources.

WLM queue configuration (concept):
Queue 1: ETL/Load queries
Memory allocation: higher (bulk operations need it)
Concurrency: lower (fewer simultaneous heavy operations)
Queue 2: Dashboard/BI queries
Memory allocation: moderate
Concurrency: higher (many small, fast queries)
Queue 3: Ad hoc analyst queries
Memory allocation: moderate
Concurrency: moderate
Query timeout: set to prevent runaway queries from
consuming resources indefinitely

The failure mode WLM prevents: without separate queues, an analyst’s unintentionally expensive ad hoc query (a missing WHERE clause, an accidental cross join) can consume enough cluster memory and concurrency slots to make the CEO’s dashboard time out during a board meeting. WLM queue isolation is the mechanism that contains one workload’s mistake from affecting every other workload sharing the cluster.

Redshift Serverless changes this model: with Serverless, WLM queue configuration is replaced by automatic resource allocation based on query complexity, with billing based on Redshift Processing Units (RPUs) consumed rather than a fixed cluster size. This trades manual queue tuning for automatic scaling, at a different cost model — relevant for workloads with unpredictable or highly variable query patterns.


Architecture Flow: Data Arriving in Redshift

S3 Silver Layer (Blog 2's partitioning + Parquet)
|
v
COPY command
(parallelizes across cluster slices -
file count/size from Blog 2 determines speed)
|
v
+------------------------------------------------+
| Redshift Cluster |
| |
| Table created with: |
| DISTKEY (customer_id) <- matches the |
| dominant join |
| pattern |
| SORTKEY (event_date, region) <- matches |
| the WHERE |
| clause |
| pattern |
| |
| Ongoing maintenance: |
| VACUUM (scheduled, post-load) |
| ANALYZE (scheduled, post-load) |
| |
| WLM queues: |
| ETL queue | Dashboard queue | Ad hoc queue |
+-------------------+----------------------------+
|
+-----------+-----------+
v v
BI Dashboard queries Spectrum queries
(fast, in-cluster (occasional, cold
distribution+sort) historical data in S3)

Failure Modes You’ll See in Production

Distribution key chosen without knowing the query pattern. The opening scenario. A table’s distribution key is set to its primary key at creation time because that seemed like a reasonable default. As the table grows and join-heavy queries against it become common, every query pays an increasing network shuffle cost that scales with table size — invisible until growth crosses a threshold where users notice.

Sort key chosen on the wrong column for actual query patterns. A table is sorted by customer_id because that seemed like the natural key, but 90% of queries filter by event_date. Block-level min/max skipping never activates for the queries that matter, and the sort key provides no benefit despite being "configured."

VACUUM never scheduled, table bloat degrading every query. A table receiving daily UPDATE operations (correcting late-arriving data) accumulates deleted-but-not-reclaimed rows for months. Query performance degrades gradually — each query scans an increasing number of logically-deleted rows — until someone finally runs VACUUM and sees dramatic improvement, retroactively revealing how much degradation had accumulated silently.

COPY command loading one enormous file. An upstream export process (not a well-partitioned Glue job) writes a single 50GB CSV file instead of multiple appropriately-sized Parquet files. The COPY command uses only one of the cluster’s many slices to process it, taking hours for a load that should take minutes with properly distributed files.

WLM misconfiguration causing dashboard timeouts during ETL loads. A nightly ETL load and daytime dashboard queries share the same WLM queue with no isolation. A large batch load consumes most of the cluster’s concurrency slots and memory, and dashboard queries running concurrently — during business hours in a different time zone than the batch window was designed for — time out or queue for minutes.

Interleaved sort key adopted without measuring actual query pattern diversity. A team adopts an interleaved sort key across four columns, believing it will “future-proof” performance for any query pattern. In practice, queries mostly filter on one or two of those columns, and the significant ongoing VACUUM REINDEX cost required to maintain interleaved sorting isn’t justified by the actual (much narrower) query diversity.


Trade-offs: What Redshift Optimizes For

Redshift optimizes for:

  • High-concurrency analytical queries with predictable, tunable performance
  • Complex multi-table joins at scale, when distribution keys are chosen correctly
  • Integration with the broader AWS ecosystem (IAM, S3, Glue Catalog, QuickSight)
  • Fixed, predictable cost for provisioned clusters running consistent workloads

Redshift doesn’t optimize for:

  • Zero-configuration performance — distribution and sort keys require deliberate, upfront design
  • Frequent row-level updates — Redshift is architecturally optimized for bulk operations, not transactional row updates
  • Unpredictable or bursty workloads on provisioned clusters — capacity is fixed unless using Serverless or manual resizing
  • Ease of schema change — altering a distribution key requires rebuilding the table, not a simple ALTER statement

The honest trade-off: Redshift gives you warehouse-grade performance for analytical workloads, at the cost of requiring genuine architectural decisions upfront that are expensive to reverse. The engineers who get the most from Redshift are the ones who understand their query patterns well enough to choose distribution and sort keys correctly the first time — not the ones who tune reactively after performance has already degraded.


Real-World Constraints

Cluster resize operations take time and can be disruptive. Changing node count or node type on a provisioned Redshift cluster (elastic resize or classic resize) takes anywhere from minutes to hours depending on data volume, and classic resize makes the cluster read-only during the operation. Capacity planning matters more for Redshift than for genuinely serverless services, because scaling isn’t instantaneous.

Concurrency scaling has its own cost model. Redshift’s Concurrency Scaling feature automatically adds transient capacity during bursts of concurrent queries, but this capacity is billed separately from the base cluster cost (with some free credit hours included). Workloads with unpredictable concurrency spikes need to budget for this separately from the baseline cluster cost.

Redshift Serverless RPU billing can be less predictable than provisioned pricing for steady, high-utilization workloads. Serverless is priced per-RPU-second consumed, which is excellent for spiky or unpredictable workloads but can cost more than an equivalently-sized provisioned cluster for workloads that run at consistently high utilization around the clock — the same “pay per use vs pay for provisioned capacity” trade-off that appears throughout AWS’s compute options.


What This Means for the Rest of the Series

Blog 7 (Glue vs EMR vs Athena): extends this article's
warehouse-vs-lake-query
comparison, specifically
contrasting Redshift with
Athena for different access
patterns
Blog 13 (Medallion on AWS): Redshift is frequently the
Gold-layer serving destination
for BI-consumed data, alongside
or instead of Athena
Blog 18 (Cost optimization): Redshift cluster sizing,
Reserved Instance purchasing,
and Serverless vs provisioned
decisions are covered in
detail as part of the broader
cost audit

Summary: The Engineering Lesson

Redshift’s performance model rewards upfront architectural thinking and punishes deferred decisions in a way that’s unusually unforgiving compared to other AWS data services. A distribution key or sort key chosen without understanding actual query patterns doesn’t produce an error — it produces a table that works, at a cost that scales invisibly with data volume until someone notices the dashboard got slow.

The six-month distribution key problem from the opening scenario wasn’t a Redshift limitation. It was a decision made correctly for the data volume that existed on day one, and never revisited as that volume and the query patterns against it evolved — exactly the kind of decision that data engineering teams need to schedule periodic review of, not just make once and forget.

Distribution keys and sort keys are not configuration details. They’re architecture decisions with the same long-term weight as a Delta table’s partition strategy or a Kafka topic’s partition count — made once, expensive to change, and worth getting right before the data volume that would reveal a mistake actually accumulates.


Next in Series

Blog 7 - AWS Glue vs EMR vs Athena: Choosing the Right Compute for the Job

Blogs 5 and 6 covered Glue and Redshift individually, in depth. This article puts them in direct comparison with EMR and Athena — the decision matrix that determines which compute service to reach for, backed by real cost calculations for the same workload run on each option.

We’ll go deep on where the boundaries actually sit, the specific data volume and workload characteristics that tip the decision one way or another, and the mistakes teams make defaulting to whichever service they learned first instead of the one the workload actually calls for.


Comment Below

What’s the most expensive distribution key or sort key mistake you’ve seen in a Redshift table?

Was it a table distributed by a high-cardinality primary key that had no relationship to how it was actually joined? A sort key chosen for the “obvious” column that turned out not to match real query patterns? VACUUM that hadn’t run in months, silently degrading every query until someone finally checked?

And — did the fix require a full table rebuild, or were you able to catch it before the rebuild became unavoidable?


Tags: aws-data-engineering, amazon-redshift, distribution-keys, sort-keys, data-warehouse, copy-command, redshift-spectrum, wlm, dataforge