How we transformed a PDF processing design in Azure into an event-driven, modular, and terraformed pipeline before deploying.
The starting point
A client came to us with a clear need:automate document processing of PDFs in Azure. The flow was ambitious — upload a document, analyze it with artificial intelligence, extract the content, and store it in a structured way — but the initial technical proposal had significant room for improvement.
Before deploying anything, we did what we always do:review the diagram with a critical eye.
What we found wasn’t wrong in conceptual terms. It covered the requirements. But architecturally it introduced unnecessary complexity, cost, and fragility.
The diagnosis: what the original design had
The initial diagram proposed the following architecture:
🔗 Azure Logic Apps
Main orchestrator of the complete flow
⚡ 3 Azure Functions
Main scraper → Specific scraper → Data extraction
⏰ Trigger schedule
Periodic timer, no reaction to real events
🏗️ Monolithic Terraform
A single block without separation of responsibilities
Why was this a problem?
1
Logic Apps as an intermediary**Azure Logic Appsis a powerful service, but in this case it acted solely as a trigger and connector between functions. That role can be natively covered byEvent Grid, event-driven and at a fraction of the cost**. Paying for Logic Apps to play the intermediary is a cost that adds no value.
2
Three cascading Functions
Thethree cascading Functionsmultiply latency, points of failure, and code to maintain. If the second one fails, the whole pipeline is interrupted. If a change needs to be made, three different pieces must be touched. The business logic did not justify such fragmentation.
3
Schedule trigger instead of events
Theschedule triggermeans the system wakes up every X time regardless of whether there is work or not. In a document processing flow, this makes no sense: the system should react when a file arrives, not ask periodically if something has arrived.
4
Unmodularized TerraformWithout Terraform modularization, the infrastructure is a monolithic block. Impossible to reuse parts in other projects, difficult to maintain, fragile to changes.
Before terraforming anything, we proposed a redesign. The client approved it. Then we finally wrote Terraform.
📐 New flow
PDF uploaded to Storage (incoming/)
↓
Event Grid
(Microsoft.Storage.BlobCreated)
↓
Single Azure Function
↓
Document Intelligence
(document analysis)
↓
OpenAI
(AI enrichment)
↓
Cosmos DB
(structured storage)
A real event triggers a real process. No intermediaries. No polling.
Storage separation by responsibility
Storage Purpose
ingest Incoming documents (pipeline trigger)
func Artifacts and internal state of the Function
processed Processed documents (available for additional flows)
Modularized Terraform Infrastructure
app/
Function · Consumption · Insights
web/
Entry layer and ingestion
data/
Cosmos DB · Storage · Connections
Each module is independently reusable in future projects.
Results in production
Complete pipeline
7.1s
From PDF arriving at storage to data being in Cosmos DB
📋 Production logs
[Information] 🔥 ProcessDocumentEvent FIRED! [Information] EventType: Microsoft.Storage.BlobCreated [Information] Starting document processing for test.pdf [Information] Processing document: test.pdf, size: 182492 bytes [Information] Document Intelligence analysis complete. [Information] OpenAI enrichment complete [Information] Document stored in Cosmos DB [Information] Executed ‘Functions.ProcessDocumentEvent’ (Succeeded, Duration: 7136ms)
What was delivered
✅ Azure Infrastructure 100% terraformed and versioned in Git
✅ Event-driven pipeline functional and tested in production
✅ Reusable Terraform modules for future projects
✅ Technical architecture documentation
✅ Training for the internal team to maintain and extend the system
Reflection
The best time to improve an architecture is before deploying it.
Reviewing a diagram costs hours. Refactoring an infrastructure in production costs weeks and real money. In this case, the switch from Logic Apps to Event Grid, the unification of the pipeline into a single Function, and the modularization of Terraform not only simplified the system — it made it cheaper to operate, easier to maintain, and ready to scale.
Infrastructure isn’t just about working. It’s about working well, costing the right amount, and being able to grow.
This case study has been anonymized. The technical data corresponds to a real project.

