Initial design

Every logic block should have a clear and concise purpose. Never pollute a logic block with extra nonessential logic. 

A Nextworld entity is a table or a set of tables like header/details. The business rules that govern the state and behavior for an entity should be implemented in one logic block or set of logic blocks. This ensures that there is no duplicate code. 

There are key principles that application developers should use as performance-enhancing tools when building logic blocks. The following are terms that application developers should keep in mind to ensure the quality and efficiency of logic block design:

  • Modularity—Defines how independent logic blocks are from one another. Modular logic blocks can be swapped in or out without causing many issues.
  • Reusability—Determines the degree to which logic blocks can be reused. The reusability of a logic block is usually related to how tightly coupled it is with other logic blocks.
  • Maintainability—Measures the ease with which a logic block can be enhanced or modified. This involves anticipating the need for future changes and structuring the logic to accommodate them.
  • Readability—Ensures that logic blocks are easy to understand and follow logically. Good comments and descriptive variable names increase the readability of the code significantly.
  • Complexity—Measures of the number of independent paths within a logic block. Avoid designing highly complex logic blocks because this can lead to a number of performance issues.

General organization

Sequence actions wisely within the logic block. Your logic block should be efficiently organized and evaluated for duplicates to ensure that no two logic blocks are accomplishing the same goal.

As you are designing a logic block, consider how new logic can be added to an existing application. New logic can be added by:

  • Attaching the new logic to an application's existing logic. Ensure that the new logic is added to the structure in a location where the new logic is relevant.
  • Creating a fit-for-purpose logic block centered specifically around the new logic if the new logic is substantial or does not fit with the existing logic of the application.
  • When developing the logic block, the Logic block inputs and outputs framework should be used where possible, even when modularizing the code. Even though modularization, makes the logic block more readable and easier to maintain, the performance of the logic could be poor because of the amount of refetching that might need to happen. By using the inputs and outputs framework, it can help eliminate the need to refetch tables, which in turn will make the logic block more performant.

Avoid designing logic blocks with deeply nested conditionals. These can be an indication of overly complex logic. In a situation like that, you can either refactor or modularize the logic block:

  • Refactor—Restructure the logic to simplify the logic flow.
  • Modularize—Break up the logic into multiple logic blocks. 

Complex logic blocks also make it difficult for developers to modify a logic block because the complexity makes the flow confusing. Simple ways to enhance readability are writing clear, concise, and complete comments and provide descriptive and consistent variable names.

Actions 

Logic block actions consume execution time that could be used for another purpose, so you must make sure that all added actions serve a required purpose. A single unnecessary or inefficient action or set of actions may not seem like something to worry about, but the action may be executed a large amount of times during a report generation causing unnecessary and significant performance issues. 

When creating a background task logic block, it is more efficient to submit one background job doing many things rather than submitting a background job for each thing separately.

Fetch performance best practices

These best practices ensure that fetch actions are designed to perform efficiently and consistently throughout Nextworld. 

It is important to understand the scope of your fetches. In other words, you must understand how many records you want included in the fetched result set. By understanding and knowing how many records you are expecting, you can make sure that you are structure the fetch correctly with an appropriate set of filtering criteria. This can also help you understand whether synchronous or asynchronous processing is appropriate. 

General best practices

Use the Limit=n query option whenever possible. This option tells the database that it can stop looking for matching records as soon as it finds the first records that matches the filtering criteria and sort order. This can help minimize the amount of work that the database has to perform in order to satisfy the query. In other words, fetching one record is more efficient than fetching 1000 when the user only wants the first one.

Test with a representative data set to better identify performance problems early on.

Be careful making assumptions about customer data. Customer data volumes, the complexity of setup data, depth of hierarchies, and so on can sometimes surprise you.

Don’t fetch from two or more tables separately when a Join table allows you to perform a single fetch. Round trips to the database (I/O) are some of the most expensive actions. 

If possible, avoid fetching the same record multiple times in a single logic flow.

Do not fetch using the unique index plus additional fields.  For example,  nwId and another field.  nwId is already unique so adding additional fields either will return the already unique record or no records. 

Fetch actions are closely linked to table indexes. When fetching, configure indexes on the table-level of an application if a logic block is performing a lot of work across a large volume of records. The indexes should be configured in the order same order as the logic block layout. For more on configuring indexes, see the following topics:

Indexes

Fetch filters

Use precise filtering criteria to exclude records that aren’t required. Don’t use minimal filtering on the fetch action itself and conditionals within the fetch loop to exclude a record from processing. If precise filtering isn’t possible, use sorting and the Exit Loop action to minimize your execution time. Sort by the significant field(s) and exit the fetch loop when the data changes. This can be a good option for a Fetch Detail Records action. You should ensure that a table index supports the fetch filtering criteria and sort. If precise filtering isn't possible, this can sometimes be accomplished by using Join tables.

When using a fetch detail, use the disposition when possible.  This will help eliminate fetching all detail rows.  For example, if your logic requires to update a Total field in the header, fetch using the disposition and add/subtract from the Total rather than fetching all details and summing.  

Fetch sorting

Avoid sorting your fetch, if possible, as it may cause unnecessary work on the database.  There are times where the logic requires records be returned in a specific order, so for these situations, use the appropriate fields to sort.  For example, if the logic relies on grouping records and performing  specific logic when one or more field values change, then sorting the records is important.   This type of "group breaking" logic requires the conditional include a check for the last record so you do not need to repeat the logic after the loop is complete.