Forum Discussion
Need Guidance Solid Structure for Incremental REST API Pipeline with Pagination in Fabric
- 5 months ago
Hey Om_Bhartiya ,
What you’re building is absolutely valid and yes, this pattern is commonly implemented in Microsoft Fabric. Your current approach is technically correct, but for production you can make it cleaner, more scalable, and easier to maintain.
Below is a solid production-ready architecture pattern that many teams use successfully.
Recommended Production Architecture (Medallion Style)
- Control Layer (Watermark + Metadata Driven)
- Instead of hardcoding logic inside activities:
- Maintain a Watermark table in Warehouse
- source_name
- last_success_epoch
- last_run_time
- status
- Read watermark at pipeline start
- Calculate:
- startDate = last_success_epoch
- endDate = current_epoch
This keeps everything restartable and idempotent.
Ingestion Layer (Bronze – Raw Landing in Lakehouse)
For REST pagination + incremental:
Recommended Structure - Instead of complex Web + Until orchestration:
- One Until loop
- Inside loop:
- Copy Activity (REST source)
- Pass curPage
- Set variable = nextPage
Stop condition:
@equals(variables('nextPage'), null)
✔ Keep pagination logic entirely inside the loop
✔ Do NOT mix schema handling here
✔ Always land raw JSON unchangedLoad into:
- Bronze table (append only)
- Partition by ingestion_date
This gives you replay capability.
Schema Handling (Do NOT rely only on OverwriteSchema)
OverwriteSchema works, but in production it can break downstream models.
Better pattern:
- Land raw JSON as string (Variant column or JSON column)
- Flatten in Notebook (Spark)
- Use: df = spark.read.json(...)
- Enable: spark.conf.set("spark.databricks.delta.schema.autoMerge.enabled", "true")
This allows controlled schema evolution in Delta tables.
Silver Layer (Flatten + Normalize)
Use a Notebook or Dataflow Gen2 to:
- Flatten nested JSON
- Standardize column names
- Cast data types
- Remove duplicates (based on business key + timestamp)
Store cleaned table in Lakehouse (Silver).
Warehouse MERGE (Upsert Pattern)
Now perform MERGE from Silver → Warehouse.
Use pattern:
MERGE INTO target t USING source s ON t.id = s.id WHEN MATCHED AND s.updated_at > t.updated_at THEN UPDATE WHEN NOT MATCHED THEN INSERTKey best practices:
- Always compare timestamps
- Never blindly overwrite
- Keep it idempotent
Watermark Update (ONLY After Success)
Very important:
Update watermark only if:
- Pagination completed
- Merge completed
- No failure in pipeline
Wrap merge + watermark update in:
- Stored Procedure
OR - Sequential Script activities
If failure occurs → watermark must NOT update.
Final Production-Ready Structure
Pipeline Flow:
- Get Watermark
- Set start/end epoch
- Until Loop (REST pagination → Bronze append)
- Notebook (Flatten + Deduplicate → Silver)
- MERGE Silver → Warehouse
- Update Watermark
- Log success/failure
This is a very common enterprise pattern in Fabric.
If this explanation helped, please mark it as the solution so others can find it easily.
If it helped, a quick Kudos is always appreciated it highlights useful answers for the community.
Thanks for being part of the discussion!
HI Om_Bhartiya,
we haven't heard back from you regarding our last response and wanted to check if your issue has been resolved.
Should you have any further questions, feel free to reach out.
Thank you for being a part of the Microsoft Fabric Community Forum!