# Best practices and common pitfalls

Good Ninox logic does more than return the right result. It should also run predictably, avoid blocking other users, and stay easy to maintain.

## **Understand transactions in Ninox**

Ninox runs database actions as transactions. A transaction groups one or more operations into a single execution step.

In practice, this means Ninox handles reading data and changing data in different ways.

### **Read transactions**

A read transaction looks up data without changing it.

Typical examples are:

* filtering records in a table
* running a query to find matching records
* reading values to display them in the app

When Ninox starts a read transaction, it works with the data state that was current at that moment. Changes saved by other users during that same query are not part of that result.

Ninox can process many read transactions at the same time. One user reading data does not usually block another user from reading data.

### **Write transactions**

A write transaction changes data.

Typical examples are:

* creating a record
* editing a field value
* deleting a record
* clicking a button that updates data
* running logic that writes values back to the database

Only one write transaction runs at a time. Other write transactions wait until the current one finishes.

That usually is not a problem. Most write transactions finish very quickly.

{% hint style="info" %}
Automations such as **On create** and **On update** run inside the same write transaction that caused them.
{% endhint %}

### **Client and server execution**

Ninox can execute logic on the client or on the server.

The client is the app running on a user's device. The server handles shared database operations in the background.

Where logic runs depends on what the action needs to do. For most users, the important point is this:

* read operations are usually lightweight
* write operations must wait their turn
* long write operations can slow down other write actions

### **Why Ninox can feel slow**

If Ninox seems slow or briefly unresponsive, a longer write transaction may be blocking the queue.

This happens when one action takes much longer than usual, and later write actions must wait.

Common causes are:

* calls to external services, for example with `http(...)`
* large data evaluations combined with `select`
* complex logic inside buttons or automations that updates many records

### **How to avoid slow write transactions**

Keep write logic focused and short.

Use these habits:

* read and prepare data first when possible
* keep API calls out of critical write flows when possible
* avoid repeated `select` queries inside loops
* test buttons and automations with realistic data volumes
* split large updates into smaller steps when possible

### **A practical way to think about it**

Use read transactions to inspect data.

Use write transactions only when you need to save a change.

The less work a write transaction has to do, the smoother the app feels for everyone.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ninox.com/ninox-scripting/automate-your-workflows/best-practices-and-common-pitfalls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
