Why Supabase is the open-source Firebase alternative - Performance Analysis
We want to understand how the work Supabase does grows as we add more data or users.
How does Supabase handle more requests or bigger databases over time?
Analyze the time complexity of fetching user data and inserting new records.
const { data, error } = await supabase
.from('users')
.select('*')
.eq('active', true)
.limit(10)
const { data: insertData, error: insertError } = await supabase
.from('messages')
.insert([{ user_id: userId, content: message }])
This code fetches up to 10 active users and inserts a new message record.
Look at the main actions that happen repeatedly as data grows.
- Primary operation: Database queries to fetch and insert data.
- How many times: Each fetch or insert is one API call, but fetching can return multiple rows.
As the number of users or messages grows, the time to fetch or insert changes.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 1 fetch call returning 10 rows, 1 insert call |
| 100 | 1 fetch call (if limited), 1 insert call |
| 1000 | 1 fetch call (still limited), 1 insert call |
Pattern observation: Number of API calls stays the same due to limits, but data size returned can grow if limits increase.
Time Complexity: O(1)
This means the number of API calls does not grow with the total data size because of query limits.
[X] Wrong: "Fetching more users always means more API calls."
[OK] Correct: Because you can limit results in one call, the number of calls can stay the same even if data grows.
Understanding how API calls scale helps you design efficient apps and explain your choices clearly.
"What if we removed the limit on fetching users? How would the time complexity change?"