Reading notes from 2017; technical explanations revised November 17, 2026. Architecture and scale observations refer to the source period.
From periodic jobs to incremental processing
The original Spark 2.1 article processes CloudTrail logs into Parquet. The useful distinction is incremental processing of newly discovered files, rather than repeatedly scanning all input. A micro-batch still has discovery, scheduling, execution, and sink latency.
maxFilesPerTrigger limits how many files a file source admits in one trigger. It does not set an end-to-end latency target. A low limit can make each batch smaller while increasing backlog if files arrive faster than they are processed.
A minimal file-source example
This separate example targets PySpark 3.5.3 and newline-delimited JSON, not CloudTrail’s nested Records envelope. Install pyspark==3.5.3 with a supported Java runtime. Place files with event_time and action fields in /tmp/events-in before starting.
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("file-etl").getOrCreate()
records = (spark.readStream
.schema("event_time timestamp, action string")
.option("maxFilesPerTrigger", 100)
.json("/tmp/events-in"))
query = (records.writeStream.format("parquet")
.option("path", "/tmp/events-out")
.option("checkpointLocation", "/tmp/events-checkpoint")
.trigger(processingTime="10 seconds")
.start())
query.awaitTermination()
The output directory holds Parquet files; the checkpoint tracks progress. Keep the checkpoint across restarts. To reset this local exercise, stop the process and remove only these three example directories after saving any wanted output. For CloudTrail, supply its actual schema and expand the Records array first.
Capacity and correctness
Compare input arrival rate, files processed per batch, batch duration, and backlog. Test a restart before treating the checkpoint as a recovery solution. Avoid changing schemas or reusing a checkpoint for an unrelated query without checking the version’s compatibility rules.
Conceptual illustration; labels describe responsibilities, not a deployment specification.