Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 31 ยท Practice and Review

Interview Questions

Prepare for backend interviews with short answers on Firebase vs Supabase, security rules, RLS, scaling, costs, modeling, realtime and auth, plus code demos.

Interviewers rarely ask you to recite an API. They ask why you would pick one platform, how you would stop a user reading another user's data, or what happens when a feature becomes popular. This lesson collects the questions that come up most for Firebase and Supabase roles, with short answers you can say out loud and a few runnable demos for the ones that are easier to show than to explain.

The platforms themselves cannot run on this site, so the code that runs here consists of stand-ins we wrote in plain JavaScript and Python; real snippets are read-only. Each answer is deliberately brief: after it, be ready for the follow-up "why?".

What interviewers probe

Trade-offs Why this platform, not another.
Security Rules, RLS and keys.
Scale and cost What breaks and what it costs.
Modeling Shapes that fit the queries.

Answer with the trade-off, then a concrete example.

1 / 2

Choosing and comparing

1. When would you choose Firebase, and when Supabase? Firebase suits mobile-first apps that want a managed document database, strong offline support and tight integration with other Google services. Supabase suits apps with relational data, SQL reporting, joins and constraints, or teams that want open-source components and the option to self-host. See Firebase vs Supabase: Choosing.

2. What is vendor lock-in here, and how do you reduce it? Firestore's data model, rules language and SDK are proprietary, so leaving means rewriting queries and security. Supabase is Postgres underneath, so data exports easily and the open components can be self-hosted, though auth, storage and realtime APIs are still Supabase-specific. Reduce lock-in by hiding the backend behind a small interface in your own code, as the Realtime Todo project does.

3. What does a BaaS give up compared with your own server? Fine control over infrastructure, arbitrary background work, and often predictable pricing at large scale. In return you skip building auth, storage, realtime and hosting. See What Is a Backend as a Service?.

Security

4. The public API key is in the browser. Is that a leak? No. Firebase config values and the Supabase anon (publishable) key are identifiers, not secrets. Security comes from rules and policies. The real secrets are the Supabase service role key and Firebase Admin credentials; they must stay on servers.

5. Explain Firestore rules are not filters. A rule decides whether a whole request is allowed. A list query that could return a forbidden document is rejected, even if some results would be allowed. The query must include constraints that prove the rule holds, for example where("ownerId", "==", uid). See Firestore Security Rules.

6. What is the difference between using and with check in RLS? using filters existing rows (which you may see, update or delete). with check validates the new values on insert and update. An update policy usually needs both so a user cannot reassign a row to someone else. See Row Level Security Policies.

7. Name three common RLS or rules mistakes. RLS not enabled on a table, using (true) left in place, and trusting a role in user-editable metadata. Others: views that bypass RLS, and Firestore rules left in test mode with allow read, write: if true. See Security Pitfalls in Both Platforms.

The next demo shows the difference between "rejecting a request" (Firestore style) and "hiding rows" (RLS style) with the same data.

JS Rules reject, RLS hides

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Realtime and offline

8. How does Firestore realtime differ from Supabase Realtime? Firestore listeners (onSnapshot) push query results, keep a local cache and work offline, with optimistic local writes. Supabase Realtime delivers Postgres changes, broadcast messages and presence over channels; it does not keep an offline cache for you. See Realtime Listeners and Offline Support and Supabase Realtime and Postgres Changes.

9. What is the cost trap with listeners? Firestore bills per document read. A listener on a large collection reads every matching document at start and each change afterwards. Limit queries, paginate, and detach listeners when a screen closes.

10. What do you do when the user closes the screen? Unsubscribe. A forgotten listener keeps reading, leaks memory and, in Firestore, costs money.

JS A listener you must unsubscribe

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Modeling and scale

11. How do you model data in Firestore? Start from the screens and queries, not the entities. Store data together that is read together, denormalize copies for fast reads, use subcollections for unbounded lists, and keep documents small (the limit is 1 MiB). See Firestore Data Model.

12. How do you model the same thing in Postgres? Normalize into tables with primary and foreign keys, add indexes for your filters, and join. Postgres handles ad hoc queries well, so you are less bound to a fixed query list. See Modeling Data: Documents vs Tables.

13. A counter updates 1,000 times per second. What now? A single Firestore document sustains only about one write per second on average, so use a distributed counter (several shard documents summed on read) or aggregate in a function. In Postgres, a single hot row also serializes updates; consider batching, or counting with count(*) on an indexed table.

14. How does each platform scale? Firestore scales automatically and charges per operation, so cost grows with traffic. Supabase is a Postgres instance: you scale by upgrading compute, adding read replicas, pooling connections and indexing. Slow queries are the usual problem, not capacity limits.

Python Sharded counter idea

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Auth

15. What is in an ID token, and who can read it? A signed JWT with the user id (sub), expiry (exp), issuer and claims. Anyone holding it can decode it, because it is only encoded. The signature proves it was not altered. See OAuth Providers, Magic Links and JWTs.

16. How do you implement roles? Firebase: custom claims set by the Admin SDK. Supabase: app_metadata or a roles table the server writes. Never use user-editable fields. See Users, Roles and Custom Claims.

17. A user is made an admin, but still sees admin pages as a normal user. Why? The old token still carries the old claims until it refreshes (about an hour by default). Force a token refresh after changing roles, or check a database record for sensitive operations.

18. How do you keep service keys safe? Environment variables on the server, never committed, never prefixed for client exposure (for example NEXT_PUBLIC_), rotated if leaked, and used only in functions.

Operations and cost

19. How do you control costs? Set budget alerts, paginate and limit queries, avoid listeners on big collections, cache, use App Check and rate limits against abuse, and review usage dashboards. Billing models differ: operation-based (Firestore) versus resource-based (Supabase compute, storage, bandwidth).

20. How do you test security? With the Firebase emulator and rules unit tests, and with supabase test db (pgTAP) or SQL scripts that switch roles. Test the negative cases: a guest, the wrong user, a missing claim.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Is the Supabase anon key a secret?

    The anon key identifies the project. Policies decide access. The service role key is the secret.
  2. 2. Why does a Firestore query without an owner filter fail under an owner-only rule?

    Firestore evaluates whether the query itself is guaranteed to be allowed.
  3. 3. How do you handle a very hot counter in Firestore?

    Sharding spreads writes across several documents, and the total is the sum of the shards.
  4. 4. A new admin still has no admin access. Most likely cause?

    Claims travel inside tokens, so they change only when a new token is issued.
  5. 5. Which is a cost risk of realtime listeners in Firestore?

    Reads are billed per document, and listeners read at the start and for every change.

Summary

  • Explain every choice as a trade-off: model, lock-in, scale, cost.
  • Public keys are identifiers; rules, policies and server-only secrets protect the data.
  • Firestore rules reject unprovable queries; RLS silently filters rows.
  • Unsubscribe listeners, shard hot counters, and refresh tokens after role changes.
  • Test the negative cases for every rule.

Next: Firebase and Supabase Cheat Sheet