How to Optimize Performance and Data Consistency When Extending Business Central

  • How to Optimize Performance and Data Consistency When Extending Business Central

    Posted by mark mckinney on June 15, 2026 at 4:41 am

    Hi Community,

    I’m currently working on extending Microsoft Dynamics 365 Business Central (cloud, latest version) using AL, where we handle high-volume transactional data (50k+ records/day). I’m facing challenges related to performance degradation and data consistency, especially when implementing custom logic in posting routines and integrating with external APIs.

    Here are the specific concerns:

    Long execution times when processing batch jobs (e.g., posting sales invoices with custom validations).

    Database locking issues, leading to occasional deadlocks when multiple users/processes run simultaneously.

    Maintaining data integrity while using temporary tables and background sessions.

    Best practices around event subscribers vs direct code modifications for scalability.

    Efficient use of SetAutoCalcFields vs CalcFields in large record loops.

    mark mckinney replied 2 weeks, 6 days ago 2 Members · 2 Replies
  • 2 Replies
  • Hardik Gupta

    Member
    June 15, 2026 at 5:52 am
    Up
    0
    Down
    ::

    Hi @markmckinney094gmail-com

    High-volume posting with 50k+ records needs smart architecture. Here’s what works:

    Performance & Batch Jobs:

    – Use SetAutoCalcFields(false) at the start, call CalcFields() only when needed

    – Use QUERY objects instead of looping, optimized at DB layer

    – Break batches into chunks via Job Queue (1000 records/job) instead of one massive batch

    – Separate custom logic from posting using Codeunit.Run(), keeps transactions clean

    Locking & Deadlocks:

    – Only use FindSet(UpdateLock) when modifying. Use read-only FindSet(false, false) otherwise

    – Keep transactions SHORT. Commit frequently, don’t wrap entire batch in one transaction

    – Avoid nested events, use a “processing flag” to prevent chain reactions

    Data Integrity with Temp Tables:

    – Use temp tables for staging/validation (isolated, no locking)

    – Validate first in temp table, commit only if all checks pass

    – Use StartSession() for background work with explicit error handling

    Events vs Code Mods:

    – Keep event subscribers lightweight, heavy logic = slow posting

    – Put business logic in separate Codeunits, call from events

    – Use OnAfter events for critical logic (order is predictable)

    CalcFields Optimization:

    – Don’t call inside loops, calculate once, store in variable

    – FlowFields are expensive at scale; consider denormalizing with a cache table if needed

    For 50k+ records, architecture looks like:

    Batch Job → Temp Table Validation → Background Sessions (chunked) → Event Subscribers → External API (async)

    Happy to review your posting routine specifics if you want to dig deeper!

  • mark mckinney

    Member
    October 1, 2026 at 2:53 am
    Up
    0
    Down
    ::

    When extending Microsoft Dynamics 365 Business Central, it is important to maintain both system performance and data consistency. A well-designed extension ensures that users experience fast processing while business data remains accurate and reliable.

    One of the best practices is to write efficient AL code. Avoid unnecessary loops, database calls, and complex calculations. Retrieve only the data you need and use filters to reduce the amount of information being processed. This helps improve system speed and reduces server load.

    Another important step is to minimize database operations. Frequent reads and writes can impact performance, especially when working with large datasets. Developers should use bulk operations when possible and avoid updating records unnecessarily.

    To maintain data consistency, always use Business Central’s standard validation methods and business rules. Instead of directly modifying data fields, use built-in functions and validation triggers. This ensures that all related checks and processes are executed correctly, preventing data errors.

    It is also recommended to use event-driven development rather than modifying standard application code. Event subscribers allow developers to add custom functionality while keeping the core system stable and easier to update in the future.

    Proper testing and monitoring are equally important. Regularly test extensions in sandbox environments to identify performance issues before deployment. Monitoring tools can help detect slow processes and optimize them when needed.

    In addition, developers should limit background processes and long-running tasks. Heavy operations can be scheduled during non-business hours to reduce the impact on users and improve overall system responsiveness.

    Finally, keep extensions simple, scalable, and upgrade-friendly. Avoid unnecessary customizations and follow Microsoft’s development best practices. A clean extension design makes maintenance easier and helps ensure smooth upgrades.

    In summary, optimizing Business Central extensions involves writing efficient code, reducing database usage, following standard validation processes, using event-driven development, and performing regular testing. These practices help organizations achieve better system performance, reliable data, and a more stable Business Central environment.

Log in to reply.

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!