skip to content

In Redshift, how do you keep a table fed continuously without scheduling COPY jobs yourself?

level: seniorimportance: nice to knowfreq 32%

answer

  1. stop writing your own scheduler
  2. a load job can watch a prefix
  3. the engine remembers which files it took
  4. a stream lands through a refreshing view
  5. falling behind retention loses records

basics

~20 s

Two managed paths. Auto-copy attaches a COPY job to an S3 prefix so Redshift loads new files as they land, tracking what it already loaded. Streaming ingestion reads a Kinesis or MSK stream through an auto-refreshing materialized view.

solid answer

~40 s

For files, **auto-copy**: you register a COPY job against an S3 prefix by adding `JOB CREATE <name> AUTO ON` to the COPY statement, and Redshift watches that prefix and loads new objects as they appear, keeping track of which files it has already ingested so nothing is loaded twice. For streams, **streaming ingestion**: create an external schema over a Kinesis Data Stream or an Amazon MSK topic, then define a materialized view with `AUTO REFRESH YES` over it. Records land as a raw binary payload column plus stream metadata, and you parse them — typically `JSON_PARSE` into a `SUPER` column — in the view or downstream. There is no S3 staging in that path, so latency is seconds rather than minutes. Both still need downstream deduplication, because file drops and streams alike are at-least-once.

code

sql · 6 lines
sql
-- Register a standing load job over an S3 prefix
COPY sales
FROM 's3://landing/sales/'
IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftLoad'
FORMAT AS PARQUET
JOB CREATE sales_autoload AUTO ON;

go deeper

for a junior

Know that Redshift can ingest without an external scheduler: a standing COPY job over an S3 prefix, or a stream read through a materialized view. Recognise the terms rather than the tuning.

for a middle

Explain each mechanism: what the load job tracks so files are not loaded twice, how an external schema plus an auto-refreshing materialized view lands stream records, and how the raw payload is parsed.

for a senior

Operate them. Monitor refresh lag against stream retention, keep the streaming view thin so refreshes stay cheap, and keep dedupe and upsert discipline downstream because delivery is at-least-once.

for a principal

Decide what freshness is worth. Weigh continuous ingest's standing cost in cluster contention and maintenance against who actually consumes the latency, and set the ingestion standard across teams rather than per pipeline.

## The problem these features solve The traditional Redshift ingest loop is an external scheduler: something notices new files in S3, issues a `COPY`, records what it loaded, and handles retries. That orchestration is real work and a real source of bugs — double loads on retry, missed files, a scheduler outage that silently stops ingest. Redshift has two managed alternatives that move the loop inside the warehouse. ## Auto-copy: a standing COPY job over an S3 prefix You define the load once, as a job attached to the COPY statement: ```sql COPY sales FROM 's3://landing/sales/' IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftLoad' FORMAT AS PARQUET JOB CREATE sales_autoload AUTO ON; ``` Redshift then watches the prefix and loads new objects as they arrive, without an external trigger. The important property is that it **tracks which files it has already loaded**, so a file that appears once is loaded once — the idempotency you would otherwise have to build into your scheduler. What it does not change is the physics from the previous questions. Files still need reasonable sizes; a producer dropping thousands of tiny objects will produce thousands of tiny loads, each paying commit and block overhead. Auto-copy removes the orchestration, not the need for sensible batching upstream. ## Streaming ingestion: Kinesis and MSK through a materialized view The streaming path skips object storage entirely. You declare an external schema over the stream source, then build a materialized view on it that refreshes itself: ```sql CREATE EXTERNAL SCHEMA kds FROM KINESIS IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftStream'; CREATE MATERIALIZED VIEW clicks_raw AUTO REFRESH YES AS SELECT approximate_arrival_timestamp, partition_key, sequence_number, JSON_PARSE(kinesis_data) AS payload FROM kds."clickstream" WHERE CAN_JSON_PARSE(kinesis_data); ``` Records arrive as a raw binary payload column alongside stream metadata — arrival time, partition key, sequence information for Kinesis; the equivalent topic, partition and offset metadata for MSK. Parsing is yours to do: `CAN_JSON_PARSE` guards against malformed records so one bad message does not fail the refresh, and `JSON_PARSE` turns the payload into a `SUPER` value you can navigate or shred into typed columns in a downstream transform. The usual shape is two layers: a thin raw materialized view that does nothing but land and parse, and a second transform that types, deduplicates and merges into the modelled fact table. ## What can go wrong - **Retention is the real deadline.** The materialized view refresh must keep up with the stream. If refreshes fall behind the source's retention window, records expire before they are read and are simply gone. Monitor refresh lag against retention, not just refresh success. - **Refresh cost is not free.** An auto-refreshing view competes for the same cluster resources as your queries. High-volume streams on a busy cluster need that contention thought about deliberately. - **At-least-once, not exactly-once.** Streams redeliver. The raw layer will contain duplicates, so the merge into the modelled table still needs the dedupe-and-upsert discipline of a batch pipeline. - **Small, frequent writes have the usual cost.** Continuous ingest means continuously appending unsorted rows and continuously creating maintenance work. Freshness measured in seconds is a real spend, not just a configuration flag. - **Not every view can refresh incrementally.** Complex SQL in the view can force a more expensive refresh, so keep the streaming view minimal and push the logic downstream. ## A third path worth naming For operational databases specifically, AWS offers zero-ETL integrations that replicate from Aurora into Redshift without a pipeline of your own. It is not part of the COPY family and its details differ, but in a design discussion about "how does data get in continuously" it belongs on the list of options alongside auto-copy and streaming ingestion. ## Choosing between them Ask what the source is and what freshness is actually required. Files arriving in S3 with minutes of tolerance: auto-copy, and keep the batches sensibly sized. Event streams with seconds of tolerance and a real business need for it: streaming ingestion, with monitoring on refresh lag versus retention. Everything else: a scheduled batch `COPY`, which remains the cheapest and most predictable option and is still what most warehouses run on.

  • How can a streaming-ingestion materialized view lose records?
    Its refreshes must outrun the stream's retention window. If the view falls behind — a paused cluster, a resource-starved refresh, a traffic spike — records age out of the source and are gone before they are ever read. Monitor refresh lag against the configured retention, and treat 'refresh succeeded' as insufficient evidence that ingest is healthy.
  • Does auto-copy remove the need to think about file sizes?
    No. It removes the scheduler, not the physics. A producer dropping thousands of tiny objects produces thousands of tiny loads, each paying commit and block overhead and leaving poorly packed storage behind. Batch upstream into files of at least a few megabytes; auto-copy is orchestration convenience, not a compaction service.
  • Data arrives continuously but the dashboards refresh hourly. Which ingestion path do you pick?
    A scheduled batch COPY, or auto-copy over hourly file drops. Continuous ingestion buys freshness nobody is consuming while paying continuously in refresh contention, unsorted rows and maintenance work. Match the ingest cadence to the consumption cadence, and reserve streaming ingestion for cases where seconds of latency have an actual business consumer.

saying these in an interview costs you the question

  • Assuming streaming ingestion gives exactly-once delivery
  • Thinking auto-copy compacts or re-batches small files
  • Treating a successful refresh as proof no records were lost
  • Choosing streaming ingest when consumers refresh hourly
  • Believing continuous ingest removes vacuum and sort maintenance

context