Development

Your custom Odoo module was written for one server. Here is what HA changes

What breaks when custom Odoo modules meet a multi-node cluster: files, sessions, locks, tokens, crons, caches and replicas, with a checklist.

CICDoo Team 9 min read

In short

On a high-availability Odoo cluster the database is the only thing every node shares. Custom modules that keep state on local disk, in process memory, in pids or in private caches break on the second node. Move that state into PostgreSQL or shared storage, lock shared rows instead of Python objects, make long-running work re-read its state, and keep read-only paths truly read-only.

On this page
  1. The assumption nobody writes down
  2. What actually changes in a cluster
  3. Eight things that break on the second node
  4. Read replicas and the meaning of readonly
  5. Upgrades, connections and logs
  6. A checklist for module authors
  7. How CICDoo runs Odoo in high availability

The assumption nobody writes down

Almost every custom Odoo module is written for one server. Not on purpose, and not in any line you could point to in a code review. It is an assumption that lives in the gaps: that the disk the module writes to is the disk it will read from next time, that a Python dictionary at the top of a file is shared by every request, that a scheduled action runs once, that the process you started is the process you can stop.

On a standalone deployment every one of those assumptions holds, so the module works, passes its tests and ships. Then the business grows, a single production server becomes a single point of failure, and someone asks for high availability. Several Odoo servers now serve the same database behind one address. A visitor's first request lands on one node and their next request on another. Nothing in the module changed, and yet it starts to misbehave in ways that are hard to reproduce, because they only happen when two requests meet on different machines.

We run Odoo clusters in production on CICDoo: a primary that owns the database, app nodes that serve the same site from other servers, and replicas that keep a live standby copy ready for failover. We also write our own Odoo modules and run them on those clusters. This article is what we learned on both sides: what changes for custom code when Odoo stops being standalone, and how to write modules that do not care which node they are running on.

What actually changes in a cluster

In a cluster, the database is the only thing every node shares. Each node has its own disk, its own Odoo processes, its own memory, its own logs and its own clock. The load balancer, in our case Cloudflare pointing one name at every healthy node, decides where each request goes, and it does not know or care which node served the previous one.

So the rule for custom code is short: anything that must be true on every node has to live in PostgreSQL, or in storage every node mounts. Everything else is a per node detail. The trouble is that a lot of module state quietly falls into the second group.

Eight things that break on the second node

1. Files on the local disk. Odoo's filestore is the obvious one: an attachment uploaded through node A is missing on node B, and the user sees a broken image or a failed download. Shared object storage for the filestore fixes Odoo's own files, but custom modules write files of their own: generated exports, cached API tokens, credential files for an integration, temporary uploads that a later step reads back. Each of those needs the same treatment. Either store the content in the database, or write it to shared storage, or make the module able to rebuild the file on whichever node needs it.

Our own AI assistant module hit this in several places at once. Provider logins were files under a per user home directory, conversation transcripts were files the next turn resumed from, and uploads were written to the node that received them. On a cluster, the second turn of a conversation could land on a node that had none of it. The fix was to make the database the source of truth: login files are mirrored in a table with a three way merge per node, transcripts are saved on the session after each turn and restored before the next, and missing uploads are written back from their attachments.

2. Sessions. Odoo keeps web sessions on the local disk by default. On a cluster a user who logs in on node A is logged out on node B. Every member needs one shared session store, which for us means the session_db module in server_wide_modules on each node. One lesson from running it: a session store that swallows a database error and returns an empty session does not fail loudly, it quietly serves requests as logged out. Treat a failure to read a session as an error, not as "no session".

3. Anything held in process memory. A dictionary at module level, a threading.Lock, an in memory counter or rate limiter: all of these exist once per worker process on one node. With six workers on each of three nodes, a "global" rate limit of 60 requests a minute is really 1,080. A lock that guarantees only one sync runs at a time guarantees it per process. If the thing you are protecting is shared, the lock has to be shared too: a SELECT ... FOR UPDATE on the row, or a PostgreSQL advisory lock.

4. Process ids. Modules that start a subprocess often store its pid so that a Stop button can kill it later. On a cluster, the Stop request may arrive on a different node, where that pid belongs to some unrelated process, or to nothing. Store the host next to the pid, only signal a process from the node that started it, and let the other nodes communicate through the database: the Stop flips a state on the record, and the node running the work notices and ends it.

5. Background work that never looks up. The same applies to work running inside a thread. A loop that only checks its own deadline will happily keep calling external APIs and writing records after a user pressed Stop on another node. Long running work should re-read its record's state on a fresh snapshot every few seconds and stop when it is no longer wanted. We found and fixed exactly this in our assistant module: Stop changed the session's state, but the in process run kept going until it finished on its own.

6. Rotating refresh tokens. Many OAuth providers issue a new refresh token on every refresh and invalidate the old one. If two nodes refresh the same login at nearly the same moment, the slower one spends a token that is already dead, and the integration is logged out until someone reconnects it. Before refreshing, lock the stored credential row, re-read it, and skip the refresh if another node has just done it. Logging out has the mirror image problem: deleting the credential on one node is not a logout until the shared copy is deleted too.

7. Scheduled actions. Odoo's cron workers coordinate through the database, so the same job is not picked up twice, but every node that runs crons competes for them, holds database connections for them and writes its own logs about them. On our clusters, app nodes run no cron threads unless you ask for it, and crons run on the primary. A module that assumes its cron runs on the same machine as the files it reads (back to point 1) will fail on whichever node picks it up.

8. Caches outside the ORM. Odoo's own caches are invalidated across processes through the registry signaling in the database. A cache a module builds for itself, a module level dictionary of settings or a file on disk, is invalidated by nothing. Node B keeps serving the old value until it restarts. Either use Odoo's ormcache and clear it through the normal API, or keep the value in the database and read it when needed.

Read replicas and the meaning of readonly

From Odoo 18, a cluster can send read only work to a replica: list and form views, reports, exports, and any route or method marked as read only. This takes real load off the primary, and it changes what "read only" means for custom code.

A route declared readonly=True that writes anything will fail on the replica and be retried on the primary, which works but wastes the round trip, and hides a mistake. A method decorated with @api.readonly must really only read. And code that writes a record and then immediately reads it back through a read only path may briefly see the replica's copy, which can be a moment behind the primary. If the next screen depends on the write, keep the read on the same request, or on the primary.

Upgrades, connections and logs

Upgrades. A module upgrade with -u changes the database schema and data. It must run exactly once, and old code must not keep serving a new schema in the meantime. On CICDoo an update to a cluster always goes through the primary: the nodes are stopped, the primary is updated and upgraded, and the nodes start again on the new code. Module authors can help by keeping migrations idempotent and by never relying on a restart of "the" server to finish a job.

Connections. Every node opens its own connections to the primary's database. A module that opens extra cursors or long transactions multiplies that by the number of nodes. Size max_connections on the primary for the whole cluster, not for one server.

Logs. Each node writes its own logs. When you debug a cluster, the request you are looking for may be in any of them, and the error on node B may be caused by a write from node A. Log enough context, the record id and the node's host name, to join them up.

A checklist for module authors

  • Every file the module writes: is it in the database, in shared storage, or rebuildable on any node?
  • Every module level variable: is it truly per process, or is it shared state in disguise?
  • Every lock: does it need to hold across nodes? Then use a row lock or an advisory lock.
  • Every stored pid: is the host stored with it, and does Stop work from another node?
  • Every long running loop: does it re-read its state and stop when asked?
  • Every OAuth refresh: is the credential locked and re-read before spending the refresh token?
  • Every cron: does it work on whichever node runs it?
  • Every custom cache: what invalidates it on the other nodes?
  • Every readonly route or @api.readonly method: does it really only read?
  • Every migration: is it safe to run once, with all other nodes stopped?

None of these makes a module slower or harder to run on one server. Code that passes this list behaves the same on a laptop, a standalone production server and a five node cluster, which is exactly the point.

How CICDoo runs Odoo in high availability

We built high availability into the hosting platform itself rather than handing customers a list of manual steps. A project can be a primary, an app node or a replica, set from its settings. App nodes on other servers join the primary's database once the primary's server lets them in, and the cluster's address points at every node that is answering, checked every few minutes. Replicas stream every change from the primary and can be promoted when the primary is lost; the other replicas follow the new primary and are rewound rather than copied again where possible. On Odoo 18 and later, members can read from a replica, and the platform closes a replica to readers when it falls behind, so Odoo falls back to the primary on its own. Nodes far from the primary can send Point of Sale and write requests to the primary's site, and the platform refuses that option unless every member shares its sessions, because otherwise users would be logged out between nodes.

Just as important, we hold our own modules to the checklist above. Our AI assistant module was written for one server like everyone's, and we went through it point by point: credentials, transcripts and uploads moved through the database, process kills tied to the node that started them, token refresh guarded by a row lock, and Stop and logout made to work from any node. The cluster features are only as good as the code running on them, and that includes ours.

If you are planning a cluster, start with the high availability documentation and the failover guide. For a look at a team running production across servers without a dedicated operations team, read how a growing Odoo team keeps 20+ instances up.

FAQ

Questions, answered

Do I need to rewrite my custom modules to run Odoo in high availability?

Usually not. Most modules only use the ORM and work on a cluster unchanged. The ones to review are modules that write files, keep state in memory, manage subprocesses or threads, refresh OAuth tokens, or build their own caches.

Does the Odoo filestore work on several nodes?

Only if every node mounts the same shared storage for it, or the filestore is moved to object storage. Without that, an attachment uploaded through one node is missing on the others.

Why do users get logged out on an Odoo cluster?

Odoo stores web sessions on the local disk by default, so a session created on one node does not exist on another. Every member needs the same shared session store, such as a database backed one.

Can scheduled actions run twice on a cluster?

Odoo's cron workers coordinate through the database, so the same job is not taken twice at once. On CICDoo, app nodes run no cron threads by default, so crons run on the primary.

Do custom modules work with Odoo 18 read replicas?

Yes, as long as routes marked readonly=True and methods marked @api.readonly really only read. A write in a read only path is retried on the primary, but it should be fixed.

The CICDoo blog

Get the next post by email

Practical notes on running Odoo in production, sent when a new post goes up. No spam, no sales sequence.

One email per new post. Unsubscribe with one click.

Run your Odoo like this

CICDoo deploys, backs up, monitors and upgrades Odoo from your Git branches, on servers you own. Talk to an engineer about your setup.

No per-seat fees. Your servers stay yours.