FreeExam

APIs and data

A backend engineer interview on designing APIs and data layers that stay correct under retries, concurrency, and change.

These prompts are original practice. They are not questions from a named employer or a live hiring loop.

  1. 1.A bike-share app sends POST /rentals and the server creates the rental. Which response best follows HTTP conventions?

  2. 2.What is the difference between 401 and 403 in an HTTP API?

  3. 3.A county library API exposes PUT /books/42. A client sends a PUT body that contains only a new title. Under standard PUT semantics, what should happen?

  4. 4.A payroll API answers bad input with 200 OK and a body like {"error": "invalid tax code"}. What is the main problem?

  5. 5.Which set of HTTP methods is defined as idempotent by the HTTP specification?

  6. 6.A clinic scheduler needs a way for patients to cancel an appointment while keeping a record of it. Which API design fits best?

  7. 7.Two admins edit the same product record. The second admin's PUT carries an If-Match ETag that no longer matches the stored version. What status should the server return?

  8. 8.A tax office API lets users request a yearly report that takes several minutes to build. How should the API respond to the request?

  9. 9.A recipe site's feed uses ?page=3 with OFFSET pagination. New recipes are added at the top all day, and users report seeing the same recipe on two pages. What is the best fix?

  10. 10.An API pages through events with a cursor that holds only the last created_at value. Some events are silently skipped between pages. What is the most likely cause?

  11. 11.A Postgres query with OFFSET 500000 LIMIT 20 is very slow even though it uses an index on the sort column. Why?

  12. 12.A public API used by mobile apps needs to rename the field "zip" to "postal_code". Many app versions stay installed for months. What is the safest approach?

  13. 13.Which change to a JSON API is backward compatible for existing clients?

  14. 14.What should a well-designed API error body contain?

  15. 15.A grain co-op API adds a new shipment status "on_hold". An older phone app crashes when it sees it. Which client-side practice would have prevented the crash?

  16. 16.A checkout service's POST /payments sometimes times out. The client retries, and some customers are charged twice. What is the right fix?

  17. 17.Two requests with the same idempotency key reach a ticketing API at the same moment. How should the server make sure only one is processed?

  18. 18.A client reuses an idempotency key from an earlier request, but this time the request body is different. What should the server do?

  19. 19.Why do retry policies add random jitter to exponential backoff?

  20. 20.Which failures should an API client usually retry automatically, with backoff?

  21. 21.A user request flows through services A, B, and C, then to a database. Each service makes up to 3 attempts on its downstream call. If the database is down, how many calls can it receive for one user request?

  22. 22.A message consumer runs UPDATE accounts SET balance = balance - 10 WHERE id = 5 for every debit message it receives. Is this safe under redelivery?

  23. 23.During an incident, a gateway's retries double the traffic to an already struggling inventory service. Which control most directly limits this?

  24. 24.A ride-hailing service calls a pricing service with no timeout. When pricing slows down, every worker thread ends up waiting and the whole service stops responding. What is the first fix?

  25. 25.A web frontend gives a request 2 seconds. The backend it calls then makes inner calls, each with its own 5 second timeout. What is the better design?

  26. 26.What does a circuit breaker do in a service that calls a flaky dependency?

  27. 27.A photo-resize worker reads jobs into an unbounded in-memory queue. During traffic spikes its memory grows until the process is killed. What is the right fix?

  28. 28.A search API is at full capacity, and more requests keep arriving. What should it do with the excess?

  29. 29.A ticketing API hangs. All threads are waiting for one of 20 database connections. A new endpoint holds its connection while it makes a slow HTTP call to a partner. What is the best fix?

  30. 30.Which anomaly can still happen under the read committed isolation level?

  31. 31.A cafe loyalty app reads a customer's points, adds 10 in application code, and writes the total back. Under read committed, some points go missing. What is the fix?

  32. 32.A warehouse rule says at least one forklift driver must be on shift. Two drivers each check that two are on shift, then clock out in separate transactions. Both commit and nobody is left. Which isolation level prevents this?

  33. 33.A Postgres transaction at serializable isolation fails with a serialization error. What should the application do?

  34. 34.A web form opens a database transaction when a user starts editing and commits when they click Save, sometimes minutes later. What is the main problem?

  35. 35.An order service writes to its own database and then calls a separate inventory service over HTTP. A teammate wants both steps to be atomic. What is the realistic approach?

  36. 36.In Postgres, what does a transaction at repeatable read isolation see?

  37. 37.What is a phantom read?

  38. 38.A wiki stores a version number on each page. Saves run UPDATE pages SET body = ?, version = version + 1 WHERE id = ? AND version = ?. How does the app detect that someone else saved first?

  39. 39.Transaction A updates row 1 then row 2. Transaction B updates row 2 then row 1. They deadlock often. What is the best fix?

  40. 40.A forum's signup code checks whether a username exists and inserts it if not. Under load, two accounts end up with the same username. What is the right fix?

  41. 41.Ten workers poll a jobs table with SELECT ... FOR UPDATE LIMIT 1 and keep blocking on the same row. Which Postgres clause lets each worker grab a different job?

  42. 42.A worker holds a lock with a 10 second lease. A long garbage collection pause freezes it for 15 seconds, another worker takes the lock, and then the first wakes and writes. What prevents the bad write?

  43. 43.A metrics service increments a shared counter from many threads without synchronization. The final total is lower than the number of events. Why?

  44. 44.A nightly billing job runs from cron on three app instances, but it must run only once. What is a sound approach?

  45. 45.When is optimistic locking a better fit than pessimistic locking?

  46. 46.A Node.js API stores the current user in a module-level variable at the start of each request handler. Under load, some users see other users' data. What is the cause?

  47. 47.A concert site reads a seat's status, sees it is free, and then marks it as sold. Some seats are sold twice. Which single statement fixes the race?

  48. 48.A table has a composite B-tree index on (region, created_at). Which query can use it most effectively?

  49. 49.A users table has an index on email, but WHERE lower(email) = '[email protected]' does a full scan. What fixes it?

  50. 50.EXPLAIN ANALYZE shows the planner expected 10 rows from a filter, but the filter actually returned 2 million. The plan chose a nested loop. What do you check first?

  51. 51.A table has an index on is_active, and 95 percent of rows are active. WHERE is_active = true uses a sequential scan. Why?

  52. 52.A support desk table has 50 million tickets. Only about 1 percent are open, and the main dashboard queries WHERE status = 'open'. Which index fits best?

  53. 53.What does it mean for an index to cover a query?

  54. 54.A high-volume events table has 14 indexes, and inserts have become slow. What is the most likely reason?

  55. 55.An order history page loads 50 orders, then runs a separate query for each order's customer. The page is slow. What is the fix?

  56. 56.A genealogy site searches names with WHERE surname LIKE '%sen'. There is a B-tree index on surname, but the query scans the whole table. Why?

  57. 57.A multi-tenant notes app runs WHERE tenant_id = ? ORDER BY created_at DESC LIMIT 20. Which index serves this best?

  58. 58.A pet adoption site stores each animal's tag ids as a comma-separated string, like "3,17,42". What is the main problem?

  59. 59.An online store copies the shipping address into each order row instead of only pointing to the customer's address. When is that the right call?

  60. 60.A budgeting app stores amounts in a floating-point column. Monthly totals sometimes end in values like 19.999999. What should it use instead?

  61. 61.An audit log collects events from servers in three time zones, each writing its local time. Events sort in the wrong order. What is the fix?

  62. 62.A gym membership system uses email as the primary key of the members table, and other tables reference it. Members often change their email. What is the better design?

  63. 63.An orders table has columns order_id, customer_id, and customer_name. What normalization problem does this create?

  64. 64.A ride app soft-deletes users with a deleted_at column and has a unique index on email. A deleted user tries to sign up again and fails. What is the fix?

  65. 65.A school system finds enrollment rows that point to student ids that no longer exist. What prevents this at the database level?

  66. 66.A product catalog has a few dozen optional attributes that vary by product type and are rarely filtered on. Price and category are filtered on constantly. What is a sensible schema?

  67. 67.You need to rename a column used by a live service without downtime. Which sequence is safest?

  68. 68.You need a new index on a large, busy Postgres table. A plain CREATE INDEX would block writes for a long time. What do you use?

  69. 69.A migration backfills a new column on 200 million rows with one UPDATE statement. What is the main risk?

  70. 70.New code reads a column that a migration adds. In what order should the migration and the code ship?

  71. 71.You want to drop a column from a table. Some app instances in the current rolling deploy still select it. What is the safe plan?

  72. 72.An ALTER TABLE waits for a lock behind a long-running report query. While it waits, every other query on that table queues behind it. What reduces this risk?

  73. 73.Why should schema migrations in a rolling deploy work with both the old and new app versions?

  74. 74.A service uses cache-aside: read from the cache, fall back to the database, and fill the cache. On a write, which approach is usually safest?

  75. 75.A news site caches its front page for 60 seconds. When the key expires, a thousand requests hit the database at once and it slows down. What is the fix?

  76. 76.At startup, a service loads 100,000 keys into its cache, all with a one-hour time-to-live (TTL). An hour later, database load spikes sharply. What is a simple fix?

  77. 77.A client sends If-None-Match with an ETag it got earlier, and the resource has not changed. What should the server return?

  78. 78.After a content delivery network (CDN) was added, users of a banking dashboard sometimes see another user's account summary. What is the most likely cause?

  79. 79.Bots request random product ids that do not exist. Each request misses the cache and hits the database. What is a cheap fix?

  80. 80.A travel site added Spanish and French. Some users now see pages in the wrong language. The pages are cached under the key /hotels/{id}. What is wrong?

  81. 81.Twenty app instances each keep an in-process cache of user settings. After a user changes a setting, some requests still show the old value. Why?

  82. 82.A queue offers at-least-once delivery. What does that mean for the consumer?

  83. 83.An email consumer acknowledges each message as soon as it receives it, then sends the email. When the consumer crashes, some emails are never sent. What is the fix?

  84. 84.One malformed message makes a consumer throw every time. The broker keeps redelivering it, and the queue behind it stalls. What is the standard fix?

  85. 85.A shop saves an order in its database, then publishes an OrderPlaced event to a broker. Sometimes the commit succeeds but the publish fails, and shipping never hears about the order. What pattern fixes this?

  86. 86.An outbox relay reads unsent events, publishes them, and then marks them sent. What must consumers handle as a result?

  87. 87.A banking ledger publishes account events to Kafka with a random partition key. Consumers sometimes apply a withdrawal before the deposit that came first. What is the fix?

  88. 88.A vendor says its queue gives exactly-once processing. In practice, how do teams usually achieve effectively-once results?

  89. 89.Video transcode jobs take about 5 minutes, but the queue's visibility timeout is 2 minutes. What will happen?

  90. 90.Consumer lag on a shipment-events topic has grown steadily for an hour. What do you check first?

  91. 91.A consumer records each processed message id in a table to skip duplicates. Why should it insert that id in the same transaction as the message's database changes?

  92. 92.A public API uses a token bucket with a capacity of 50 and a refill of 10 tokens per second. What traffic does it allow?

  93. 93.A fixed-window limiter allows 100 requests per minute. How can a client go over the intended rate?

  94. 94.An API runs on 10 instances. Each one limits a client to 100 requests per minute using its own local counter. What is the real limit per client?

  95. 95.A rate-limited API rejects a request with 429 Too Many Requests. What should the response include to help well-behaved clients?

  96. 96.A login endpoint is under a password-guessing attack. What should the rate limiter key on?

  97. 97.A logged-in user of a utility billing portal changes the URL from /invoices/1001 to /invoices/1002 and sees a neighbor's invoice. What is the bug?

  98. 98.An app uses stateless JSON Web Token (JWT) access tokens that last 30 days. A stolen token cannot be revoked quickly. What is the usual fix?

  99. 99.A team hides the Delete button from non-admins in the React app. A non-admin calls DELETE /projects/9 directly and it works. What is the fix?

  100. 100.A hotel booking platform has internal services that call each other over a private network with no checks. What is the stronger design?

  101. 101.How should a backend store user passwords?

  102. 102.A request goes through five services, and a user reports one slow, failed request. How do you make it easy to follow that request across all of them?

  103. 103.A developer adds user_id as a label on a request latency metric. The metrics system slows down and its costs jump. Why?

  104. 104.Average latency for a library catalog API looks fine at 80 ms, but users still complain it is slow. What should you look at?

  105. 105.Why do teams prefer structured logs, such as JSON with named fields, over free-form text lines?

  106. 106.A team gets paged every time CPU passes 80 percent, yet users rarely notice any problem. What is a better primary alert?

  107. 107.A payroll service logs full request bodies at info level, including Social Security numbers. What should be done?

  108. 108.A trace for a slow clinic booking request shows 40 calls to the same patient service, one after another, each taking about 30 ms. What is the most likely fix?

  109. 109.A fintech service logs each request but has no metrics. Engineers want to know the error rate over the past week. What is the main drawback of deriving it from logs?