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.

    Hardik Gupta replied 1 month, 1 week ago 2 Members · 1 Reply
  • 1 Reply
  • 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!

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!