Quick revision
The short answer
Orders, customers and payments are related records that must change together and stay consistent, which is exactly what a relational database gives us: transactions, constraints, joins and flexible queries. PostgreSQL adds broad tooling, JSONB for the semi-structured parts and first-class Spring Data JPA and Hibernate support. We add Redis, a search engine, a document store or a time-series store only for a proven need, because every extra database costs operations, and we choose what the team can run well.
What to remember
In this answer, we saw why a relational database such as PostgreSQL is the usual default for orders, customers and payments: transactions, constraints, joins and flexible queries protect related financial data, and PostgreSQL adds broad tooling, JSONB and strong Spring Data and Hibernate support. We looked at when to add Redis, a search engine, a document store or a time-series store, and why we start with one database, add others for proven needs, and choose what the team can operate well.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Orders, customers and payments are related records that must change together and stay consistent, which is exactly what a relational database gives us: transactions, constraints, joins and flexible queries. PostgreSQL adds broad tooling, JSONB for the semi-structured parts and first-class Spring Data JPA and Hibernate support. We add Redis, a search engine, a document store or a time-series store only for a proven need, because every extra database costs operations, and we choose what the team can run well.
Why this question is asked
Choosing the database is one of the first decisions for a new service and one of the hardest to change later. Interviewers ask this question to check that our default has reasons behind it, and that we know when those reasons stop applying. In this answer, we will look at what relational databases guarantee and why order and payment data needs it, see why PostgreSQL in particular is a common default for Spring Boot services, go through the cases where another store is the right addition, and explain why we start with one database and add more only when a need is proven.
1What a Relational Database Guarantees
A relational database stores data in tables with a fixed set of columns, and links tables through keys. Four features matter for an order service. Transactions group several changes so that they all happen or none do: creating an order, its lines and a payment record, and reducing stock, either succeed together or are rolled back together. Constraints let the database itself reject bad data: a NOT NULL total, a foreign key so an order cannot point to a customer that does not exist, a CHECK that an amount is positive, a UNIQUE key on a payment reference to prevent double charges.
Joins let us combine tables in queries, so we can store each fact once and still ask questions across them, such as 'all unpaid orders of customers in Germany'. And flexible queries mean we do not have to know all our questions in advance: next year's report or support tool can query the same tables in new ways, with an index added if needed.
Notice that the last statement fails in the database, whatever bug the application has. For money, having the database enforce the rules is a safety net worth a lot.
2Why PostgreSQL Is a Common Default
Among relational databases, PostgreSQL has become a frequent default for several reasons. It is open source with a permissive licence, so there is no licence cost or vendor lock-in, and every major cloud offers it as a managed service. Its tooling is broad: monitoring with pg_stat_statements, backups with pgBackRest, migrations with Flyway or Liquibase, local tests with Testcontainers.
It also handles the parts of a service that are not neatly tabular. JSONB columns store JSON documents in a binary form that can be indexed and queried, so payment provider responses or product attributes that vary by category can live next to the relational data. And it works well with the Spring stack: Spring Data JPA and Hibernate support it fully, with a dedicated dialect, so a Spring Boot service can map entities to tables with little configuration.
3When to Consider Something Else
Some needs are better served by a specialised store, usually in addition to PostgreSQL rather than instead of it. Redis, an in-memory key-value store, is the usual choice for caching hot data and for counters such as rate limits, where microsecond reads matter more than durability. For full-text search with relevance ranking, typo tolerance and facets across millions of products, Elasticsearch or OpenSearch do far more than PostgreSQL's built-in text search, which is fine for simpler cases.
A document store such as MongoDB can fit data whose shape varies a lot from record to record and is read as whole documents, such as content management. A time-series store such as TimescaleDB, which is a PostgreSQL extension, or InfluxDB suits metrics and sensor data that arrive as huge streams of timestamped points. In each case the specialised store usually holds a copy or a derived view, while orders and payments, the records of truth, stay in the relational database.
| Need | Consider | Orders and payments stay in |
|---|---|---|
| Hot reads, sessions, rate limits | Redis | PostgreSQL |
| Full-text search, facets, relevance | Elasticsearch or OpenSearch | PostgreSQL, search indexes a copy |
| Highly variable whole documents | document store | PostgreSQL, or JSONB first |
| Metrics and sensor streams | time-series store | PostgreSQL |
| Order, customer and payment records | nothing else | PostgreSQL |
4Start With One and Add for Proven Needs
Every additional database brings operational cost: it needs backups and restore tests, monitoring, upgrades, security patches, capacity planning and on-call knowledge. It also brings consistency work: if search holds a copy of products, something must keep that copy in sync, and someone must handle the times it falls behind. For a new service with modest traffic, PostgreSQL alone can usually handle caching-like reads, simple search and JSON data well enough for a long time.
So the sensible path is to start with one database and add another when we can show the need: search relevance that users complain about, read latency that a cache would fix, a data volume PostgreSQL struggles with. Finally, the team matters. A database the team knows how to tune, back up and debug at 3 a.m. is worth more than a theoretically better one nobody understands. If the company already runs MySQL well, MySQL is a perfectly good relational choice too.
5Follow-up questions
Can't we just use JSONB for everything and skip the schema?
We could, but we would lose most of what makes the database useful for orders: foreign keys, NOT NULL and CHECK constraints, type safety and efficient joins. JSONB is best for the genuinely variable parts, next to normal columns for the fields we query and constrain.
Why not use Redis as the main store since it is fast?
Redis keeps data in memory, offers only limited transactions and queries, and its durability depends on configuration. It is excellent as a cache in front of the real store, but payment records need durable storage, constraints and flexible queries.
Is MySQL a worse choice than PostgreSQL?
Not for this kind of service. Both are mature relational databases with good Spring support. PostgreSQL has richer features such as JSONB indexing, more index types and stricter SQL behaviour, but a team with strong MySQL experience can build an excellent order service on it.
6Conclusion
In this answer, we saw why a relational database such as PostgreSQL is the usual default for orders, customers and payments: transactions, constraints, joins and flexible queries protect related financial data, and PostgreSQL adds broad tooling, JSONB and strong Spring Data and Hibernate support. We looked at when to add Redis, a search engine, a document store or a time-series store, and why we start with one database, add others for proven needs, and choose what the team can operate well.
Open with
Orders, customers and payments are related records where consistency matters, so I would start with a relational database. Transactions let me create an order, its payment and the stock change atomically.
Then, if they want more
Constraints like foreign keys, NOT NULL, CHECK and a unique payment reference make the database itself reject bad data, which is a real safety net for money. Joins and flexible SQL let me answer questions I did not plan for, like support and finance reports.
PostgreSQL in particular is a common default: it is open source and available as a managed service everywhere, it has good tooling for monitoring, backups, migrations and Testcontainers, JSONB covers semi-structured parts like provider responses, and Spring Data JPA and Hibernate support it fully.
I would consider other stores for specific needs, usually in addition: Redis for caching or rate limits, Elasticsearch or OpenSearch for real full-text search, a document store for highly variable documents, a time-series store for metrics.
But every extra database means backups, monitoring, upgrades and sync work, so I would start with one and add others only for a proven need, and pick something the team can operate well.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6
- 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.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
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 "For a new Spring Boot service storing orders, customers and payments, why is a...": https://scrivio-interview-library.netlify.app/databases/database-operations/b072ff06e1/