Sequelize timezone option vs application-level UTC conversion in a moleculer-db service
0 reputation · 14 Aug 2026, 18:04 UTC
0 reputation · 14 Aug 2026, 18:04 UTC
I'm designing a Moleculer service that uses moleculer-db with the Sequelize adapter, and date handling across regions is the one decision I haven't settled. The service will run on multiple broker nodes, potentially on machines with different system time zones, and clients in several regions will read the stored timestamps.
Sequelize documents a global timezone option that stores dates in UTC and converts them to the configured zone on retrieval. The alternative is to leave that option unset and handle all conversion in application code, normalizing to UTC before writes and formatting per-request on reads. My concern is that the documented behavior notes the retrieval conversion depends on the driver or the database itself, and I haven't confirmed whether that is consistent across MySQL and PostgreSQL, both of which are candidates for this deployment.
Assume a recent Moleculer 0.14 and Sequelize 6 setup.
Given a multi-node cluster, is relying on Sequelize's timezone option sufficient to guarantee identical stored values on every node, or does the driver-dependent conversion make application-level UTC normalization the safer choice?
If I omit the option, does each node's local system time affect what gets written through the moleculer-db adapter?
What is the most practical way to verify the round-trip behavior against the actual production database before committing to either approach?
35275 reputation · 14 Aug 2026, 19:23 UTC
Using sequelize with timezone: '+00:00' is sufficient to guarantee that every broker node writes the same UTC value to the database, regardless of the node’s local time zone. The conversion is performed by Sequelize before the query is sent to the driver, so the driver’s session time zone or the database’s own conversion logic does not introduce divergence.
When the timezone option is omitted, Sequelize falls back to the Node process’s local time zone. In a heterogeneous cluster this means that two nodes with different TZ settings could serialize the same JavaScript Date into different UTC strings, resulting in inconsistent stored values. In that scenario, normalizing dates to UTC in application code is the safer approach.
timezone setting to all Date values before they reach the database driver.TIMESTAMP and PostgreSQL TIMESTAMPTZ store UTC internally; the database does not alter the value once it is sent.DATETIME) is used, Sequelize’s timezone conversion may not be applied consistently.timezone set, the driver receives a UTC string and simply stores it.TIMESTAMP (MySQL) or TIMESTAMPTZ (PostgreSQL) column.
const utcDate = new Date('2026-10-11T09:03:12Z');
await Model.create({ createdAt: utcDate });
const result = await sequelize.query('SELECT created_at FROM table LIMIT 1', { type: sequelize.QueryTypes.SELECT });
console.log(result[0].created_at); // Should output 2026-10-11 09:03:12
TZ=America/New_York and another with TZ=Asia/Tokyo, both pointing to the same database. Perform the same write and read test.
timezone: '+00:00' they must match; without it they will differ.
process.env.TZ, perform the write, then query the shared database to assert equality.
To fine‑tune the recommendation, could you confirm the column type you plan to use for timestamps (e.g., TIMESTAMP vs DATETIME) and the database driver versions (mysql2, pg)? These details affect how Sequelize’s timezone option interacts with the underlying DB.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.