Scrivio Interview library
DesignAdvanced8 min read · updated 12 November 2026

Your company serves customers in 40 countries. Reports, invoices and searches differ because of time zones, collations, decimal rounding and case rules spread across Java code and SQL. What platform-level conventions would you set?

I would set a few platform rules that every service follows: store instants as timestamptz or UTC and convert to a customer's zone only at the edges and in reports with an explicit zone; choose one collation strategy and treat collation library upgrades as index-affecting changes; define money rounding once in the domain layer with BigDecimal and per-jurisdiction rules; use a calendar dimension for fiscal periods and holidays; and test with locale-sensitive data such as the Turkish dotless i and the German sharp s.

Why this question is asked

When a company grows from one country to forty, small local habits in code turn into disagreements between systems: an invoice says one total, the report another, and a search finds a customer in one service but not in another. The causes are almost always the same four: time zones, collations, decimal rounding and case rules, each implemented slightly differently in Java and in SQL. Interviewers ask this design question at senior levels because the answer is about conventions and ownership more than about any single function. In this answer, we will go through each area, explain what goes wrong, set the convention, and say where the rule should live, then look at testing that keeps the rules honest.

1Why the Numbers Disagree

Every disagreement has the same shape: two pieces of code answer the same question with slightly different rules. A Java service computes an invoice total by rounding each line, while a SQL report rounds the sum. A search in Java lowercases with the server's default locale, while the database compares with its collation. A daily report cuts days at UTC midnight while the customer portal uses local midnight. Each choice is defensible on its own; together they produce three different numbers.

So the goal is not to pick clever functions but to decide each rule once, write it down, put it in one place that every service uses, and test it with data that would expose the differences.

Platform conventions at a glance
AreaConventionWhere it lives
Timestore instants (timestamptz / UTC); convert at edgesAPI layer, reporting queries
Zone of a customerIANA zone name stored per customer or sitecustomer profile
Collationone strategy: ICU or builtin in PG, utf8mb4_0900 in MySQLschema standards
Case-insensitive matchnormalise or citext; Locale.ROOT in Javashared library
Money roundingBigDecimal, rule per jurisdiction, oncedomain layer
Fiscal periods, holidayscalendar dimension tabledata platform
Test datalocale-sensitive fixtures in every suiteshared test kit

2Time: Store Instants, Convert at the Edges

An instant is a point on the global timeline, the moment a payment happened, independent of where anyone was. We store instants as timestamptz in PostgreSQL, TIMESTAMP in MySQL, which both store UTC, and as Instant or OffsetDateTime in Java. We never store a local wall-clock time without its zone for something that happened at a moment, because it cannot be converted back reliably around daylight saving changes.

Conversion to a customer's local time happens only at the edges: when we display a time, when we interpret a user's local input, and in reporting queries, which state the zone explicitly with AT TIME ZONE and an IANA zone name such as 'Europe/Berlin', never with a fixed offset and never by relying on the session time zone. Each customer or site record stores its zone name, so a report for Brazilian customers knows to use 'America/Sao_Paulo'.

There is one exception worth naming: future local events, such as a store opening at 09:00 local time next year, should be stored as local time plus zone, because the zone's rules may change before the date arrives.

3Collations: One Strategy, and Upgrades Treated as Risky

A collation is the set of rules for comparing and sorting text: whether 'a' equals 'A', where 'U+00E4' sorts relative to 'a' and 'z', and so on. Different collations give different answers to equality and order, so two services with different collations disagree about whether two names are the same.

We choose one strategy per database engine. In PostgreSQL that usually means ICU collations, which behave the same on every operating system, or the builtin provider added in PostgreSQL 17 for a stable C.UTF-8 behaviour when linguistic sorting is not needed; in MySQL, the utf8mb4_0900 family. Case-insensitive matching is done one way everywhere, for example by storing a normalised search column or using citext.

There is a nasty operational trap here. An index on a text column stores values in collation order. If the collation library changes its rules, as glibc did in version 2.28 when many Linux distributions upgraded, existing indexes are suddenly in the wrong order, and lookups can miss rows or unique constraints can let duplicates in. So OS and library upgrades on database hosts are treated as index-affecting changes: we check collation versions, which PostgreSQL tracks and warns about, and rebuild affected indexes with REINDEX.

4Money: Round Once, in the Domain Layer

Rounding rules for money differ by country and by purpose. Some jurisdictions require tax rounded per line, others per invoice; some use half up, where 2.5 becomes 3, others banker's rounding, half even, where 2.5 becomes 2 and 3.5 becomes 4, which avoids a systematic upward bias over many operations. Some currencies have no minor unit, and Switzerland rounds cash amounts to 0.05.

These rules belong in one place, the domain layer, implemented with BigDecimal and an explicit RoundingMode, never with double. SQL reports then read the amounts the domain computed and stored, rather than recomputing with SQL's ROUND, whose behaviour differs between numeric and floating types and between engines.

Java
BigDecimal net = new BigDecimal("19.99");
BigDecimal vat = net.multiply(new BigDecimal("0.19")); // 3.7981
vat.setScale(2, RoundingMode.HALF_UP); // 3.80
new BigDecimal("2.345").setScale(2, RoundingMode.HALF_EVEN); // 2.34
new BigDecimal("2.355").setScale(2, RoundingMode.HALF_EVEN); // 2.36
double d = 0.1 + 0.2; // 0.30000000000000004 never for money

A small MoneyRules component, given a jurisdiction and a purpose, returns the scale and rounding mode. Invoices, refunds and reports all call it, so they cannot drift apart. Amounts are stored as numeric with a fixed scale, or as integer minor units with the currency beside them.

5A Calendar Dimension Instead of Date Arithmetic

Fiscal years that start in April, weeks that start on Sunday in one country and Monday in another, public holidays, business days for payment terms: if every query computes these with date arithmetic, each one gets a slightly different answer. A calendar dimension is a table with one row per date and columns for fiscal year, fiscal quarter, ISO week, local week, and a holiday or business-day flag per country. Reports join to it instead of computing. Ten years of dates is under 4,000 rows, trivial to store, and when a country adds a holiday, one update fixes every report.

6Case Rules in Java, and Testing With Real Data

Java's toLowerCase() and toUpperCase() without arguments use the JVM's default locale. On a server whose default is Turkish, 'TITLE'.toLowerCase() becomes 't' followed by the dotless i, U+0131, so a key lookup for 'title' fails. For technical strings, such as keys, codes and email addresses, we always pass Locale.ROOT; for text shown to users, we pass the user's locale on purpose.

Java
"TITLE".toLowerCase(Locale.of("tr")); // "tıtle" dotless i, U+0131
"TITLE".toLowerCase(Locale.ROOT); // "title"
"straße".toUpperCase(Locale.ROOT); // "STRASSE" the length changes from 6 to 7
"STRASSE".toLowerCase(Locale.ROOT); // "strasse" not "straße": the round trip is lossy

None of these show up with ASCII-only test data, which is exactly why they reach production. The shared test kit should include fixtures with Turkish names containing the dotted and dotless i, German words with the sharp s, accented names such as Jose with an acute accent, names in non-Latin scripts, amounts that land exactly on rounding halves, and timestamps a few minutes either side of midnight and of daylight saving changes in several zones. Every service runs its relevant tests against these fixtures, and cross-service tests compare invoice totals with report totals for the same data.

7Follow-up questions

How do you roll these conventions out across existing services?

Publish them as a short standard with a shared library for money rules and time conversion, apply them to new code immediately, and fix old code where incidents or reconciliations show disagreement. A reconciliation job that compares invoice totals with reporting totals every night finds the services that still differ.

Should the database server time zone be set to UTC?

Yes, as a safe default, and connections should set it explicitly too. But correctness should not depend on it: queries that need a local day state the zone explicitly, so they give the same answer whatever the session setting.

Who owns these rules?

Money rounding is owned with finance and tax experts, collation and time standards by the platform or database team, and the calendar dimension by the data platform. Each rule has a named owner and a change process, because a change in any of them alters numbers in many places.

8Conclusion

In this answer, we traced disagreeing numbers to rules implemented differently in Java and SQL, and set conventions for each area: store instants and convert at the edges with explicit IANA zones, choose one collation strategy and treat library upgrades as index changes, round money once in the domain layer with BigDecimal and per-jurisdiction rules, use a calendar dimension for fiscal periods and holidays, use Locale.ROOT for technical strings, and test with locale-sensitive data that ASCII fixtures would never reveal.

What to say in the interviewAbout 90 seconds aloud

Open with

The underlying problem is that the same rule is implemented several times, slightly differently, in Java and in SQL, so I would set a handful of platform conventions and put each rule in one owned place.

Then, if they want more

For time, we store instants, timestamptz or UTC timestamps and Instant in Java, and convert to the customer's zone only at the edges: display, input parsing, and reporting queries, which always name an IANA zone explicitly instead of relying on the session. Each customer stores its zone name.

For text, we pick one collation strategy per engine, ICU or the builtin provider in PostgreSQL, utf8mb4_0900 in MySQL, and one way of doing case-insensitive matching. We also treat OS and ICU or glibc upgrades as index-affecting changes, because a collation change can leave indexes in the wrong order, so we check collation versions and reindex.

For money, rounding rules depend on jurisdiction, half up or banker's rounding, per line or per invoice, so they live once in the domain layer using BigDecimal with an explicit rounding mode, and reports read stored amounts rather than recomputing with SQL ROUND.

Fiscal periods, weeks and holidays come from a calendar dimension table instead of date arithmetic in every query. In Java, technical strings use Locale.ROOT. And every service tests with locale-sensitive fixtures: Turkish dotless i, German sharp s, midnight and daylight saving edges.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 17
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your company serves customers in 40 countries. Reports, invoices and searches differ...": https://scrivio-interview-library.netlify.app/databases/sql-fundamentals/9914a70793/