The Decision That Shapes Your Architecture#
Every D365 developer faces this question regularly: should this logic live in a plugin or a Power Automate flow? The answer isn't always obvious, and getting it wrong has real consequences for performance, maintainability, and cost.
When to Use Plugins#
Plugins are your tool when you need synchronous, transactional logic that must execute before the user sees a response.
Use plugins for:#
- Data validation that must block save operations
- Complex calculations that affect the current record
- Pre-operation logic (setting default values, computing fields)
- Operations requiring transactional consistency
- High-frequency operations (thousands of executions per hour)
// Example: Pre-operation plugin for order validation
public void Execute(IServiceProvider serviceProvider)
{
var context = serviceProvider.GetService<IPluginExecutionContext>();
var target = (Entity)context.InputParameters["Target"];
var quantity = target.GetAttributeValue<int>("quantity");
var available = GetAvailableStock(target.GetAttributeValue<EntityReference>("productid"));
if (quantity > available)
{
throw new InvalidPluginExecutionException(
$"Requested quantity ({quantity}) exceeds available stock ({available})."
);
}
}Plugin advantages:#
- Synchronous execution — user gets immediate feedback
- Full transaction support — rolls back on failure
- No licensing cost per execution
- Sub-second execution for well-written code
When to Use Power Automate#
Power Automate excels at orchestration, integration, and async workflows that involve multiple systems.
Use Power Automate for:#
- Multi-step approval workflows
- Integration with external services (email, Teams, SharePoint)
- Scheduled or batch processing
- Non-critical notifications and updates
- Workflows that business users need to modify
Power Automate advantages:#
- Visual designer — business analysts can understand and modify flows
- 400+ connectors to external services
- Built-in retry logic and error handling
- No code deployment required
The Decision Framework#
I use three questions to make this decision:
- Does it need to be synchronous? → Plugin
- Does it involve external systems? → Power Automate
- Will business users need to modify it? → Power Automate
The gray area#
Some scenarios genuinely could go either way. For these, I consider:
- Execution volume: High volume (1000+ daily) favors plugins (no per-execution licensing concerns)
- Complexity: If the logic requires complex C# patterns, plugins are more testable
- Team capability: If your team has strong C# skills, plugins offer better debugging and unit testing
The Hybrid Approach#
In practice, the best architectures use both. I typically implement:
- Plugins for core business logic and validation
- Power Automate for orchestration and integration
- Custom APIs (plugin-based) that Power Automate flows can call for complex operations
This gives you the performance of plugins with the flexibility of Power Automate.
Common Mistakes#
- Using Power Automate for validation that should block saves — users see success, then get a notification that something failed
- Using plugins for everything — over-engineering simple notification workflows
- Not considering the testing story — plugins are unit-testable with FakeXrmEasy, flows are harder to test
Conclusion#
There's no universal right answer. The best choice depends on your specific requirements, team capabilities, and architecture. But having a consistent decision framework saves time and prevents the inconsistency that makes systems hard to maintain.