How snowplow/snowplow-s3-loader works
Project type and purpose
• This is a Scala-based streaming data loader service (“Snowplow S3 Loader”) that reads records from an Amazon Kinesis stream and writes them in either LZO or GZip format to Amazon S3.
• It is structured as a core module (modules/main) plus an LZO-specific plugin (modules/lzo), all built with sbt.
File structure
• Top-level build files: build.sbt, project/* define dependencies and build settings.
• modules/main: the core pipeline: configuration loader, Kinesis source executor, processing, serializer interfaces, connector implementations, S3 emitter, monitoring.
• modules/lzo: a plugin providing an LzoSerializer and corresponding Main entrypoint.
• Tests mirror the main code structure, demonstrating the key components and their responsibilities.
• config/config.hocon.sample shows runtime configuration (Kinesis stream names, AWS credentials, bucket names, path patterns, serializer choice).
Architecture outline
a. Main components
• External Systems:
• AWS Kinesis (input stream)
• AWS S3 (output bucket)
• StatsD / Snowplow Tracker (monitoring sinks)
• Service modules:
• Main Runner
• KinesisSourceExecutor
• Processing Engine (Batching, Common logic, DynamicPath builder)
• Serialization Strategy (GZipSerializer or LzoSerializer)
• S3Loader / KinesisS3Emitter
• Configuration loader (reads HOCON, supplies settings to all components)
b. Relationships and data flows
1. Configuration loader initializes the application.
2. Main Runner invokes KinesisSourceExecutor on a schedule or thread.
3. KinesisSourceExecutor pulls records from Kinesis and groups them into a Batch.
4. Batch is sent to the Processing Engine, which:
– Applies any transformation (e.g., IdentityTransformer)
– Computes the S3 target path via DynamicPath
5. The selected Serializer (strategy pattern) encodes the Batch (either LZO via Protobuf+ElephantBird or GZip line separator).
6. S3Loader / KinesisS3Emitter uploads the blob(s) to S3; in LZO mode it also writes .lzo.index files.
7. Monitoring component records stats and events to StatsD and SnowplowTracking.
8. Loop continues.
c. Architectural patterns and principles
• Modular plugin architecture: core vs. LZO plugin
• Strategy pattern for serializers (ISerializer interface / GZipSerializer / LzoSerializer)
• Pipeline/streaming pattern: Source → Processors → Sink
• Single responsibility: each connector, serializer, processor and monitor module has one clear role.
d. Key technologies and libraries
• Scala + sbt project build
• AWS SDK for Kinesis and S3
• ElephantBird + Protocol Buffers (for LZO blocks)
• Hadoop LZO index format
• GZip streams
• Typesafe Config (HOCON)
• StatsD client & Snowplow Tracking SDK
Essential elements
• Don’t overcomplicate: focus on the minimal set of major components and their interactions.
• Both data flow (record movement) and control flow (triggering/execution, configuration).
• Extensibility: how swapping in LzoSerializer vs GZipSerializer does not change the overall pipeline topology.