Blog Post

Fabric Updates Blog
4 MIN READ

Building Event-Driven Applications in Microsoft Fabric with Business Events and User Data Functions

robece-msft's avatar
robece-msft
Icon for Microsoft Employee rankMicrosoft Employee
2 months ago

Fabric User Data Functions (UDFs) provide a serverless execution environment for running custom business logic inside Microsoft Fabric. Developers can use UDFs to build APIs, orchestrate workflows, integrate with external systems, invoke AI models, and work with data stored across Fabric services such as Lakehouse, Warehouse, SQL Database, and Eventhouse. UDFs can be invoked directly by applications, called through APIs, scheduled to run automatically, or triggered in response to business events.

When combined with Business Events, Fabric User Data Functions become the action layer of an event-driven application. Business Events detect meaningful business signals such as inventory shortages, abandoned carts, trending content, or shipment delays. User Data Functions consume those events, retrieve the required business and AI context, execute decision logic, and perform actions such as updating systems, triggering workflows, invoking AI models, or publishing follow-up events. Together, Business Events and User Data Functions enable organizations to move from monitoring and alerts to automated, intelligent, real-time business processes.

Why pair User Data Functions with Business Events

When combined with Business Events, User Data Functions become the action layer of an event-driven application. They provide the business logic, orchestration, and integration capabilities needed to transform business signals into automated outcomes.

  • Serverless execution — Run business logic without managing infrastructure.
  • Event-driven automation — Automatically respond to business events in real time.
  • Built-in access to Fabric data — Work with Lakehouse, Warehouse, SQL Database, Eventhouse, and other Fabric assets.
  • AI-powered decisions — Combine business context with AI models to generate intelligent actions.
  • Integration and orchestration — Connect Fabric with external APIs, SaaS applications, and enterprise systems.
  • Scalable and reusable logic — Centralize business rules that can be invoked from applications, workflows, APIs, or events.

Architecture pattern

Business Events

Meaningful signals such as InventoryBelowThreshold, CartAbandoned, ContentTrending, or ShipmentDelayed.

Real-Time Hub

Discovery, routing, and subscription layer for business events.

Functions

Business logic and orchestration layer that reacts to events and calls downstream systems.

Fabric data + AI

Context from Lakehouse, Warehouse, Eventhouse, SQL DB, and models to make the action smarter.

How it works in code

A User Data Function publishes a Business Event by connecting to an Event Schema Set defined in Real-Time Hub and calling PublishEvent with a typed payload. The platform wraps the payload in a CloudEvents envelope automatically — you only write the business data. The alias in the @udf.connection decorator must match the connection name configured in Manage connections inside the UDF item.

Python — Basic UDF pattern: publish a Business Event

import fabric.functions as fn
udf = fn.UserDataFunctions()
# Connect to the Event Schema Set defined in Real-Time Hub
@udf.connection(argName="businessEventsClient", alias="RetailInventory")
@udf.function()
def publish_inventory_event(
businessEventsClient: fn.FabricBusinessEventsClient,
product_id: str,
store_id: str,
current_stock: int,
threshold: int
) -> str:
event_data = {
"product_id": product_id,
"store_id": store_id,
"current_stock": current_stock,
"threshold": threshold,
}
businessEventsClient.PublishEvent(
type="Retail.Inventory.LowStockThreshold",
event_data=event_data,
data_version="v1"
)
return "Event published"

CloudEvents envelope

Business Events uses the CloudEvents standard as its wire format. When you call PublishEvent, the platform handles routing, deduplication, and delivery to every subscriber automatically. You define the business payload — the platform takes care of the rest.

Use case summary

Use case

Business event

Function role

Business outcome

Supply Chain

InventoryBelowThreshold

Choose supplier, validate stock, calculate replenishment, trigger PO or transfer.

Prevents stockouts, reduces manual monitoring, and creates an auditable replenishment flow.

Ecommerce

CartAbandoned

Look up customer profile and cart context, decide eligibility, generate the best recovery action.

Improves conversion with personalized offers and closes the loop through CRM and follow-up events.

AI Supply Chain Copilot

ShipmentDelayed

Orchestrate mitigation combining order, inventory, route, SLA, and AI-generated plan context.

Turns a delay signal into an executable mitigation plan with customer-facing updates.

1. Supply Chain: Prevent Stockouts with Business Events + Functions

Problem

Manufacturers lose production time when critical inventory falls below safety stock across warehouses.

Business event

InventoryBelowThreshold

Function logic

Choose supplier, validate available stock, calculate replenishment, and trigger PO or transfer.

Outcome

Prevents stockouts, reduces manual monitoring, and creates an auditable replenishment flow.


Figure 1. Supply Chain: Prevent Stockouts with Business Events + Functions.

Explore the full scenario walkthrough on the developer site for schema definition, publisher code, and step-by-step instructions.

2. Ecommerce: Recover Abandoned Carts in Real Time

Problem

Customers add products to cart but do not complete checkout, causing revenue leakage.

Business event

CartAbandoned

Function logic

Look up customer profile and cart context, decide eligibility, and generate the best recovery action.

Outcome

Improves conversion with personalized offers and closes the loop through CRM and follow-up events.


Figure 2. Ecommerce: Recover Abandoned Carts in Real Time.

Explore the full scenario walkthrough on the developer site for schema definition, publisher code, and step-by-step instructions.

3. AI Supply Chain Copilot: Auto-Mitigation for Shipment Delays

Problem

Shipment delays impact SLA commitments and customer experience unless mitigation happens quickly.

Business event

ShipmentDelayed

Function logic

Orchestrate mitigation by combining order, inventory, route, SLA, and AI-generated plan context.

Outcome

Turns a delay signal into an executable mitigation plan with customer-facing updates.

Figure 3. AI Supply Chain Copilot: Auto-Mitigation for Shipment Delays.

Explore the full scenario walkthrough on the developer site for schema definition, publisher code, and step-by-step instructions.

Resources

Credits

This article was developed in collaboration with Sunitha Muthukrishna (@mk_sunitha), whose contributions and insights helped shape the scenarios and technical direction presented here.

To continue, explore the community guide and the official Business Events documentation

Updated 2 months ago
Version 1.0
No CommentsBe the first to comment