Quick revision
The short answer
Every service gets its own role per environment, created and granted from code, so there are no shared accounts. People get no standing write access to production: they request temporary, approved, expiring access through an access broker using their SSO identity, and analysts work on replicas or a warehouse with masked data. A sealed break-glass credential covers emergencies with alerts and review, and a regular job reconciles the real grants against the code.
What to remember
In this answer, we designed access for 200 services and 50 analysts as four separate paths. Services get one role per environment from code with no shared accounts, engineers get temporary approved access through an SSO-backed broker, analysts work on replicas or masked warehouse data, and a sealed break-glass credential handles emergencies with alerts and review. Logging and a reconciliation job keep the real grants equal to the declared ones.
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.
Every service gets its own role per environment, created and granted from code, so there are no shared accounts. People get no standing write access to production: they request temporary, approved, expiring access through an access broker using their SSO identity, and analysts work on replicas or a warehouse with masked data. A sealed break-glass credential covers emergencies with alerts and review, and a regular job reconciles the real grants against the code.
Why this question is asked
At 200 services and 50 analysts, database access stops being something a DBA can manage by hand. Every manual grant becomes a permanent, undocumented exception, and after a year nobody can say who can read what. Interviewers ask this design question at senior level to see whether we can build a model that is secure by default and still lets people work, including on the worst night of an incident. In this answer, we will look at the four kinds of access in turn: applications, humans, analysts and break-glass, and then at how auditing and reconciliation keep the model true over time.
1The Shape of the Model
The core idea is to separate access by who is asking and why, and to give each kind of access its own path with its own rules. Applications need constant, narrow access. Engineers need occasional, sometimes broad access during incidents. Analysts need wide read access, but not to raw personal data and not on the primary. Emergencies need a path that works even when the normal tools are down.
Underneath all of it sit the same PostgreSQL building blocks: roles with and without LOGIN, group roles that carry privileges, and grants on schemas and tables. The design decides who is allowed to create those roles and grants, and how.
| Who | Identity | Access | Lifetime |
|---|---|---|---|
| Service | one role per service per environment | DML on its own schema only | permanent, managed as code |
| Engineer | SSO user via access broker | read by default, write only on approval | hours, then revoked |
| Analyst | SSO user on replica or warehouse | read on masked data | while in the team |
| Break-glass | sealed credential | owner-level on one cluster | single use, then rotated |
2Application Accounts as Code
Each service gets a group role that holds its privileges, such as orders_rw, and a login role per environment, such as orders_prod, that is a member of it. Grants are written in a repository, either as SQL migrations run by a platform pipeline or with an infrastructure-as-code tool that has a PostgreSQL provider, and they are reviewed like any other code change. A service owner who needs a new table in another team's schema opens a pull request that the other team approves.
The reason to make this code instead of tickets is that code gives us history, review and a declared state we can compare against reality later. Credentials are generated by the platform and delivered through a secret manager, ideally as short-lived dynamic users, never typed by a person. Migrations use a separate migrator role, so no running service has DDL rights.
3Human Access Without Standing Privileges
Standing access means a person has permission all the time, whether they need it or not. For production databases we want the opposite: by default an engineer has no login at all, and when they need one they ask for it. An access broker is a service that sits between people and databases. It authenticates the engineer with the company's SSO, checks the request against a policy, asks for approval when needed, creates a temporary PostgreSQL role with VALID UNTIL set a few hours ahead, and records the session.
7 messages in order. Play them, or step through them one at a time.
The broker creates and removes the role; the engineer never holds a lasting password.
Notice that read access and write access follow different rules. Read access to a non-sensitive schema for on-call engineers might be auto-approved for two hours, while write access to a payment cluster needs a second person's approval and a ticket reference. Several products and cloud features provide this broker (cloud IAM database authentication, secret managers with dynamic database users, commercial access proxies), and which one fits depends on the platform; the model is the same.
So when someone leaves the company, disabling their SSO account removes every database access they had, because none of it was a separate password.
4Analysts Away From the Primaries
Fifty analysts running exploratory queries on production primaries is both a performance risk and a privacy risk. A single badly written join can hold locks or exhaust memory, and analysts rarely need real names, emails or card details to answer business questions. So analysts work on read replicas for near-real-time needs, or more often on a warehouse fed by a pipeline that masks or removes personal fields on the way. Their access is granted to SSO-backed groups by team, on masked views or masked copies, and access to the few unmasked datasets is a separate, approved and audited role.
5Break-Glass Access
Break-glass access is the emergency path for the night when the access broker itself or SSO is down and production is broken. It must exist, because otherwise people keep secret back doors. It is a powerful credential per cluster, stored sealed in a vault that requires two people to open it, or split between two holders. Any use fires an alert to the security team at once, the session is logged in full, the credential is rotated immediately afterwards, and every use gets a post-incident review that asks why the normal path was not enough. We also test break-glass in drills a few times a year, because an emergency credential nobody has tried is likely not to work.
6Auditing and Reconciling Grants
A model is only as good as our ability to prove that reality matches it. Two things run continuously. First, logging: log_connections and a session audit extension such as pgAudit record who logged in and what privileged statements they ran, shipped to central storage that database administrators cannot edit. Second, reconciliation: a scheduled job reads the actual roles, memberships and grants from the catalog of every cluster and compares them with the declared state in code.
Any difference is either a manual change that must be removed or a real need that must be added to code. We also look at usage: a grant that no statement has used for 90 days is a candidate for removal. Quarterly, owners re-certify the access of their services and teams, which is a short review because the data is already collected.
7Follow-up questions
How do you handle a service that legitimately needs data owned by another service?
Preferably through the other service's API, so the owning team keeps control of its data. When direct database access is justified, for example for a read-heavy internal report, the consuming service gets a read-only grant on specific views in the owner's schema, approved by the owning team in the grants repository, so the dependency is visible and reviewable.
Why not let senior engineers keep read access to production at all times?
Because standing access is exactly what an attacker uses after stealing a laptop or a session token, and it also drifts into habits like running ad hoc fixes. Auto-approved, time-limited read access gives seniors nearly the same speed while leaving an audit trail and no lasting credential.
How do you roll this out over existing clusters full of old grants?
Cluster by cluster: import the current grants into code as the starting state, mark obviously unused ones from usage data, migrate services to their own roles, and then switch reconciliation from report-only to enforcing. Starting in report-only mode avoids breaking services on day one.
8Conclusion
In this answer, we designed access for 200 services and 50 analysts as four separate paths. Services get one role per environment from code with no shared accounts, engineers get temporary approved access through an SSO-backed broker, analysts work on replicas or masked warehouse data, and a sealed break-glass credential handles emergencies with alerts and review. Logging and a reconciliation job keep the real grants equal to the declared ones.
Open with
I would design four separate access paths. For applications, every service gets its own role per environment, with privileges on a group role and grants kept in a repository and applied by a pipeline, so there are no shared accounts and every grant has a review and history.
Then, if they want more
Credentials come from a secret manager, ideally as short-lived dynamic users, and migrations use a separate migrator role so the runtime role has no DDL. For people, nobody has standing write access to production.
Engineers authenticate through SSO to an access broker that checks policy, asks for approval for sensitive clusters or for writes, and creates a temporary PostgreSQL role with VALID UNTIL, so leaving the company or an expired window removes access automatically.
Analysts do not touch primaries at all; they use read replicas or, usually, a warehouse fed with masked data, with unmasked datasets behind a separate audited role. For emergencies there is a sealed break-glass credential per cluster that needs two people to open, alerts security on use, is rotated afterwards and always gets a review.
Finally, pgAudit and connection logs go to central storage, and a scheduled job compares actual grants in the catalogs with the declared state and removes drift and unused grants.
About this answer
- Last updated
- 12 November 2026
- 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 "Design a database access model for 200 services and 50 data analysts across PostgreSQL...": https://scrivio-interview-library.netlify.app/databases/database-security/5108b2f686/