Skip to main content
Kiran Brahma
All writing

O9X Build Log 20: The Black Swan Tax

Part 20 of O9X Build Logs

I spent a week migrating data for O9X, and decided to start beta testing from 23rd February onwards. But on 22nd evening, I could not log in to the app. I checked Cloudflare, which had no outage. When I opened the Supabase website, I noticed that it was blocked.

Indian ISPs had blocked the supabase.co domain (primarily Jio). Every API call heads to the supabase.co domain, so my app was unreachable without a VPN or a DNS hack. I spent weeks mapping compliance risks, schema failures, and data migration gaps, but an ISP block was the last thing on my mind. I had to find a fix quickly, else my team would consider this a failed project.

Across Reddit, other Indian developers were facing the same issue. Even Supabase acknowledged the issue, and recommended raising a complaint with their ISP to resolve it. An ISP could take its own sweet time to fix the issue, but I needed to find a fix by morning.

After a bit of research, I had three options in front of me:

  1. Upgrade my free Supabase account to a paid plan. I could use a custom domain to overcome the block.I wasn't keen as I wasn't clear how the ISP applied the block. If my custom domain resolves to a supabase.co domain at the DNS level, I am back to square one.
  2. Update DNS details across all devices to use Cloudflare’s 1.1.1.1 or Google’s 8.8.8.8 DNS. This would be a logistical nightmare as my staff works across different cities. I would need to walk everyone through how to change the DNS setting on their phone. I did not outright reject it, but kept it as my fail-safe.
  3. The third option was to reroute my app's API calls through Cloudflare Workers. Every call that my app makes goes to Cloudflare, which routes it to Supabase and returns the result. My app was already hosted on Cloudflare Workers, so a Cloudflare outage would already take my app down; rerouting my API calls added no additional risk.

Once I decided on rerouting my API calls via Cloudflare, I spent the next hour on how to do it. I asked Claude to research this approach to build a stage-wise plan. I decided to test the approach for a single API call, so that AI could identify the errors and fix them. I deployed the updated code to Cloudflare to test it in production. It worked and I began updating the remaining API calls. It took me a total of six hours to update my entire collection.

I couldn't migrate Google Sign-in authentication as it is dependent on Supabase’s own OAuth system, which connects to supabase.co directly. Rerouting it meant I would need to build my own custom OAuth server and all. Luckily, most of my team was using email sign-in, so I dropped fixing the Google Sign-in issue and moved on.

By the end of the day, my app was up and running. Supabase keeps users logged in for fifteen days, so anyone from my team who had already signed in did not need to sign in again. I made most of the fixes in the late evening (22nd Feb), so my team did not face any issue when they logged in on the morning of 23rd Feb.

I tested the extra latency by running the same API call twice: once through the Cloudflare proxy, and once directly to Supabase over a VPN. The proxy added between 22 and 40 milliseconds to an API call. When my staff requests data, it requires one to three seconds before the data is shown to them. The additional 0.04 seconds was too low to impact their perception of the app's performance.

The app's request volume shot up after the change. Before, my app averaged around 200 requests for every supervisor user, but after the change the average went up to 360. Cloudflare provides a generous 100,000 requests in their free limit, so my app could support 250+ users without any issue.

I could make the change in my code quickly as every function and API call was well documented. After every session, I ask the AI to document every decision. My claude.md/agents.md has an instruction that every function needs a comment on five specific fields: logic, inputs, outputs, error handling, and assumptions. I built a set of rules on coding standards and package choices along with my business goals to ensure AI doesn't invent its own rules and system.

I spend around 10 to 20 percent of session limits on documentation. The same documentation helped to resolve a major issue. It also ensures that my code stays consistent.

The migration also closed a small security gap. A lot of client code runs in the browser, so any logged-in user could inspect and see my app's API call patterns. Now my API calls are routed through Cloudflare, so they are no longer visible to logged-in users.

The migration did lead to an issue. Cloudflare Workers' free tier has a hard limit of 10 milliseconds of CPU time per request. Before the migration, my average CPU time was 19 milliseconds. After the migration, it is 23 milliseconds. I don't see any errors due to low and uneven traffic to my app. Cloudflare enforces this limit softly. However, once my app's traffic becomes steady, Cloudflare might enforce the limits strictly.

I will need to investigate and evaluate how to reduce CPU usage per request across my app, but it is a problem for another day.