REST API Integration Pipeline
Build a resilient external REST API ingestion pipeline that extracts paginated customer activity events, manages rate limits and network transient errors, validates raw payloads, and publishes curated analytical datasets to Snowflake.
Project Brief
Understand the business requirement and engineering challenge of integrating external APIs.
Business Scenario
A modern retail organization relies on a third-party customer engagement platform that records real-time user actions, web interactions, in-app purchases, and support events. This partner system exposes an external REST API for data extraction.
The analytics and customer experience teams require these activity streams to calculate customer engagement scores, conversion rates, and multi-channel marketing effectiveness. However, because the API is hosted externally, the data engineering team cannot control its availability, payload consistency, or response times.
Development Objective
Design and develop a production-ready ingestion pipeline that retrieves activity events across paginated endpoints, persists raw API responses for auditability, parses and validates complex JSON structures, removes duplicate events, standardizes Silver activity records, and delivers aggregated activity metrics to Snowflake.
Expected Outcome
The core challenge is balancing distributed processing with external API limits. You must structure ingestion to handle pagination, token auth, transient HTTP errors (5xx/429), and schema drift without hard-coding credentials or causing pipeline failure on dirty payloads.
Source System
Inspect the external API contract, pagination mechanics, and payload structure.
Source Overview
The source system is an external REST API endpoint providing paginated JSON responses of customer activity events. For development and testing, the API can be simulated or mocked using local mock servers or static JSON generators.
Example API Payload
Each API response contains a JSON payload with paging metadata and an array of activity records:
{
"status": "success",
"page": 1,
"page_size": 100,
"has_more": true,
"data": [
{
"activity_id": "ACT-884920",
"customer_id": "C1001",
"activity_type": "purchase",
"activity_timestamp": "2026-08-30T10:15:00Z",
"amount": 125.50,
"currency": "USD",
"device_type": "mobile",
"location": "Bengaluru",
"metadata": {
"channel": "app",
"session_id": "S98762",
"ip_address": "103.21.124.5"
}
}
]
}Activity Schema Attributes
Known Source Constraints
The source contract defines how the API behaves under both optimal and degraded conditions. Your pipeline must be resilient against network drops, authentication expiry, rate limits, and corrupted payloads.
Expected Architecture
Design a resilient multi-stage architecture from API ingestion to Snowflake delivery.
Target Architecture Flow
The pipeline decouples network extraction from distributed data processing. Raw API responses are landed immediately into Bronze storage, parsed and validated into Silver Delta tables, and aggregated into Gold analytics datasets.
Layer Responsibilities
Architectural Expectations
Never perform complex business logic directly in the extraction client. Extract to Bronze first, then use PySpark for distributed validation, deduplication, and transformation.
Development Requirements
Implement the functional components required to extract, validate, transform, and publish API data.
Developer Responsibilities
The implementation must fulfill the following 15 engineering requirements across extraction, data quality, transformation, and target publishing.
API Client & Request Handling
Implement a robust HTTP client for external API communication.
Pagination Mechanism
Traverse paginated endpoints until all records for the extraction window are retrieved.
Authentication & Secrets Separation
Securely manage API credentials and tokens.
Raw Bronze Persistence
Persist unmodified raw JSON payloads to cloud storage / Bronze Delta.
JSON Parsing & Unnesting
Parse nested JSON arrays into structured PySpark DataFrames.
Schema Validation & Typing
Enforce strict data type casting and required field validation.
Activity Deduplication
Prevent duplicate activity events across overlapping extractions.
Retry Policy & Transient Error Handling
Handle transient network failures and 5xx server responses gracefully.
Rate Limit Management
Comply with API provider rate limits to prevent 429 throttling.
Silver Activity Transformation
Produce the clean, curated Silver customer activity Delta table.
Dead-Letter Quarantine
Isolate malformed or invalid records without pipeline termination.
Gold Activity Aggregation
Generate curated metrics and business KPIs from Silver records.
Snowflake Target Publishing
Publish curated activity and aggregation tables to Snowflake.
Operational Logging & Metrics
Provide comprehensive telemetry for every pipeline execution.
Configuration Management
Externalize all pipeline parameters across environments.
You may choose whether to extract via Python requests before dispatching to Spark, or use custom Spark UDFs/datasources. Document your architectural choice and justify its performance and maintainability.
Testing Requirements
Validate pipeline resilience against pagination, network errors, malformed payloads, and duplicates.
Required Test Scenarios
The developer must validate both successful ingestion paths and failure-recovery modes.
External integrations will fail in production. Demonstrating how your pipeline handles 429s, 503s, and dirty payloads is just as important as verifying normal multi-page extraction.
Acceptance Criteria
Verify that the implementation satisfies the production Definition of Done.
Definition of Done
The task is complete when all 12 criteria are satisfied and backed by code, test evidence, and query outputs.
Code alone is insufficient. Deliverables must include test execution outputs, mock API scenarios, and query reconciliation results.
Developer Deliverables
Submit code, configuration, tests, and execution proof for review.
Required Deliverables
Provide the following 11 artifacts in your project repository:
Ensure your mock API harness allows another engineer to run your entire test suite without requiring real external credentials.
Engineering Constraints
Adhere to operational and technical boundaries for enterprise API integrations.
Required Boundaries
The solution must strictly comply with the following 10 constraints:
Violating any of these constraints (such as committing hard-coded tokens or dropping bad records silently) will result in immediate code review rejection.
Suggested Project Structure
Recommended repository layout for production REST API pipeline development.
Recommended Project Layout
Structure your repository to separate API client logic, PySpark transformation layers, tests, and environment configurations:
DEV-003-api-integration-pipeline/
โ
โโโ README.md
โ
โโโ config/
โ โโโ dev.yaml
โ โโโ staging.yaml
โ โโโ prod.yaml
โ
โโโ src/
โ โโโ api/
โ โ โโโ client.py # HTTP client, pagination & retry logic
โ โ โโโ auth.py # Token manager & auth headers
โ โ โโโ mock_server.py # Local mock API for testing
โ โ
โ โโโ ingestion/
โ โ โโโ bronze_writer.py # Raw JSON landing & metadata tracking
โ โ
โ โโโ transformations/
โ โ โโโ silver_activity.py # JSON parsing, unnesting & deduplication
โ โ โโโ gold_analytics.py # Daily summary & user KPI aggregation
โ โ โโโ quarantine.py # Dead-letter quarantine handler
โ โ
โ โโโ publishing/
โ โโโ snowflake_loader.py # Snowflake staging & merge loader
โ
โโโ notebooks/
โ โโโ 01_api_extraction.py
โ โโโ 02_silver_curation.py
โ โโโ 03_gold_publishing.py
โ
โโโ tests/
โ โโโ test_api_client.py
โ โโโ test_pagination.py
โ โโโ test_retries_backoff.py
โ โโโ test_silver_parsing.py
โ โโโ test_deduplication.py
โ
โโโ docs/
โโโ architecture.md
โโโ api_contract.mdModule Responsibilities
Separating API extraction from Spark transformations ensures that changes to external API schemas or endpoint formats do not break downstream analytical aggregations.
Submission Checklist
Final quality checklist before submitting DEV-003 for peer engineering review.
Final Review Checklist
Verify every checklist item before submitting your development work:
Submit DEV-003 only after the API client, Bronze raw storage, Silver Delta curation, Gold analytics, Snowflake sync, and test suites have been thoroughly validated.