Hello Sitecorians! 👋
Whenever a new requirement comes in, like "download the assets and share via email" or "send a report to stakeholders every month", the first design question is the same: should this be a Content Hub script, or an Azure Function?
Both can read and write Content Hub data. Both can be started by a trigger. But they are built for very different jobs, and picking the wrong one leads to slow saves, timeouts, or a lot of extra infrastructure for a simple rule.
In this blog, I compare the two, share a simple decision guide, and map it to real solutions from my own blogs this year.
So, let's get started! 😊
What Each Option Is
Content Hub scripts
Scripts are C# code that runs inside Content Hub, managed in Manage → Scripts. The main types are:
- Action: started by a trigger, in the Pre-commit, Security, Validation, Audit or Post phase.
- Metadata processing: runs after an asset is processed, to work with its metadata.
- User pre-registration, User post-registration and User sign-in: run around user creation and login.
- Shared: reusable code that other scripts reference.
What you need to know about their limits:
- They are restricted: only certain libraries are allowed (the Content Hub SDK,
System.Linq,System.Text,Newtonsoftand so on), and some, likeSystem.Environment, are blocked. - They can't call REST APIs. Sitecore's guidance says so directly.
- Sitecore recommends keeping the run time below 10 minutes. After 12 minutes, the script is treated as stuck.
- They are meant for atomic operations on one entity, not bulk jobs.
Azure Functions
An Azure Function is your own code, running outside Content Hub, in your Azure subscription. It talks to Content Hub through the REST API or the SDK, with an OAuth client. It can be started by:
- A Content Hub action: API call (an HTTP call to the function), Azure Service Bus or Azure Event Hub (a message the function picks up).
- A timer (for example, monthly).
- Anything else: another system, a queue, or a manual run.
On the Manage → Actions page, you can see both kinds side by side: Action script actions that run code inside Content Hub, and Azure Service Bus actions that hand the work to a queue for something outside to pick up. Heavier processes, like generating banners for an advertisement variant, use the Service Bus route:
Side by Side
Content Hub script | Azure Function | |
|---|---|---|
Where it runs | Inside Content Hub | Your Azure subscription |
Started by | Trigger (with an Action script action), asset processing, user events | API call / Service Bus / Event Hub action, timer, other systems |
Can block a save or show a message | Yes (Pre-commit, Validation, in process) | No, it runs after the event |
Calls external APIs | No | Yes |
Libraries | Restricted list | Anything you need |
Run time | Keep under 10 minutes | Long jobs possible (with the right plan, or Durable Functions) |
Best for | One entity, one event, fast rules | Bulk, scheduled, long-running or integration work |
Secrets | No place for external secrets | Key Vault / app settings |
Deploy | Content Hub packages | Your CI/CD pipeline |
Logs | Script telemetry, action audit log | Application Insights |
Extra cost and ops | None | Hosting, monitoring, OAuth client |
The row that decides most cases is the third one: if the user must be stopped or must see the result immediately, only a script can do it.
The Decision Guide
Ask these three questions, in this order:
- Must it block the save or give the user an answer straight away? Validation, required checks, default values before saving. Only a script can do this, in the Pre-commit or Validation phase, running in process.
- Does it need an external system? Sending data to another platform, calling an AI service, reading from an ERP, using a secret. Scripts can't call REST APIs, so this is an Azure Function, started by an API call or Azure Service Bus action.
- Is it bulk, scheduled or long-running? Thousands of entities, a monthly job, anything that could get near the 10-minute limit. That is an Azure Function with a timer, batches, or Durable Functions.
If the answer to all three is no, it is a small rule on one entity, and a script in the Post phase, running in background, is the simplest and cheapest choice.
Real Examples from My Blogs
Here is how the guide played out in solutions I built this year:
Requirement | Choice | Why |
|---|---|---|
Script (Validation) | The user must be stopped, with a message, before the change is saved. | |
Script (Pre-commit) | The value has to be there in the same save, and it is a simple rule on one asset. | |
Script (Post, in background) | No user feedback needed, and the work stays inside Content Hub. | |
Azure Durable Function | Runs on a schedule, counts users across the whole instance, and sends email. | |
External .NET tool | Thousands of entities, a CSV backup and a typed confirmation. Far too big and risky for a script. | |
External console tool | Scans every asset and works in paced batches, so it must not run inside the platform. |
The last two are not Azure Functions, but they follow the same rule: bulk work runs outside Content Hub, through the API. Whether that is a function, a console tool or a pipeline step depends on how often it runs and who starts it.
The Hybrid Pattern
Many real requirements need both. For example: when an asset is approved, check it has a brand, and then send it to an external platform.
- A Validation script (in process) checks the brand and stops the approval if it is missing. The user gets the message straight away.
- A trigger on the approved state runs an Azure Service Bus action, which puts a small message (the entity ID) on a queue.
- An Azure Function reads the message, loads the asset through the API, and calls the external platform, with retries and logging.
The script keeps the user experience fast and correct. The function does the slow, external work without blocking anyone. Using a queue in between also means the external system can be down for a while without losing anything.
Best Practices
For scripts:
- Prefer in background. Use in process only when the user really needs the result before the save finishes.
- Keep them small and atomic: one entity, one job. No bulk loops.
- Narrow the trigger conditions, so the script only runs when the fields it cares about change. This matters most on high-traffic definitions like M.Asset.
- Consolidate scripts that run on the same event, to avoid race conditions.
- Use the async methods, and check Script telemetry for slow or noisy scripts.
For Azure Functions:
- Send IDs, not data, in the action payload. API call and Service Bus payloads are limited (headers 64 KB, values 256 KB), and the function can load fresh data itself.
- Put the API URL and connection strings in Content Hub settings, so they can be different per environment.
- Keep secrets in Key Vault, and use a dedicated OAuth client and integration user with only the permissions it needs. (My 401 debugging blog shows what happens when the policies are missing.)
- Make the function idempotent: the same message processed twice must not do damage.
- Use Durable Functions or queues for long jobs, and Application Insights for logs and alerts.
Sources
- Scripting guidance and scenarios (Sitecore Accelerate)
- Script types
- Script restrictions
- Action types
- Use of triggers
Conclusion
Scripts and Azure Functions are not competitors. They solve different problems. Use a script when the logic is small, about one entity, and the user needs the result in the same save. Use an Azure Function (or other external code) when the work talks to another system, runs on a schedule, or touches many entities. And when a requirement needs both, let the script guard the save and hand the heavy work to a function through a queue.
Three questions, in order: Must it block or reply instantly? Does it need an external system? Is it bulk or long? That is usually all it takes to choose.
I hope this helps you in your Content Hub journey! If you have any questions, feel free to drop a comment below. 😊
Stay tuned for more! 👋


