Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Database Consistency Under Concurrency
00:00
5 left

Database Consistency Under Concurrency

MediumSQL · PostgreSQL

Problem

Explain your strategy for database consistency in a highly concurrent environment.

Write a PostgreSQL query that audits stored account balances against their posted ledger entries. Treat credits as positive, debits as negative, ignore non-posted entries, and safely handle NULL amounts.

Output

  1. One row per inconsistent account, including account_id, currency, opening_balance, current_balance, expected_balance, and difference.
  2. Include only accounts whose stored balance differs from the calculated balance, ordered by account_id ascending.

Schema

accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
currencyVARCHAR(3)ISO currency code
opening_balanceNUMERIC(18,2)Balance before ledger activity
current_balanceNUMERIC(18,2)Stored current account balance
ledger_entries
ColumnTypeDescription
entry_idPKINTUnique ledger entry identifier
account_idINTAccount affected by the entry
entry_typeVARCHAR(30)Ledger event type
amountNUMERIC(18,2)Monetary amount of the entry
statusVARCHAR(20)Processing status of the entry
Tablesaccountsledger_entries
Interviewer

Your question is Database Consistency Under Concurrency. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.