Building a Serverless Startup on Cloudflare Workers

Tejas Mehta built cClip, a cross-platform file transfer tool, to solve a personal pain point: getting homework from his Android phone to his MacBook. The app has since grown into a fully serverless product, with Cloudflare Workers at the center of its architecture.

cClip lets users share files and links between any devices, regardless of operating system. The backend relies primarily on Workers and KV, but Mehta also integrated several third-party SaaS services for specialized functions: Firebase for authentication and real-time messaging, RevenueCat for mobile subscription management, Stripe for billing, and Backblaze B2 for cloud storage.

This approach points to a model where developers compose applications from multiple managed services, communicating via APIs and webhooks rather than hosting everything themselves.

Client Strategy

Supporting every major platform required a pragmatic approach. Rather than build five separate native applications, Mehta used Flutter for a single shared codebase covering iOS, Android, and web. Flutter Web also enabled an Electron wrapper for Windows and Linux users who prefer a desktop app.

Flutter Web had limitations during development. WebWorker support was missing, so Mehta relied on JavaScript for tasks like encryption. He also intended to use StreamSaver.js for streamed decryption, which reduces memory consumption when downloading larger files.

For macOS, Mehta chose a native Swift app instead of the Flutter version. The macOS and iOS clients share code for password hashing, file uploads, downloads, and encryption, and the Swift app offers performance benefits over the web-based route.

Backend Architecture

The backend comprises five main services: B2 for storage, Firebase Auth and Firebase Database, RevenueCat for subscriptions, and Workers as the orchestrator in between.

Workers handles all sensitive API calls. The authentication flow begins when Firebase Auth validates a user's identity—via Google, Apple, or email/password sign-in. Once the user is authenticated, the client receives an idToken, a JWT containing the user's UID. Every sensitive operation, such as file access or subscription changes, goes through a Worker that verifies this token in the Token header before proceeding.

Workers also acts as a gatekeeper for file operations. When a request comes in, the Worker checks the user's identity, the requested file location, and subscription status. If all checks pass, it authorizes the action with B2 and returns the relevant details.

Storage, Messaging, and Subscriptions

Files larger than 25MB were impractical to store in Workers KV, so Mehta turned to B2 as a primary filestore. Since Cloudflare's Bandwidth Alliance includes Backblaze, file transfers to and from users don't incur egress fees. Workers acts as the authentication and authorization layer in front of every B2 operation.

Firebase Database handles real-time communication with all clients, storing metadata like subscription status. Firebase Cloud Messaging sends push notifications to devices when needed.

RevenueCat sits between cClip and the mobile app stores, providing a unified view of subscription data across Apple, Google Play, and Stripe. This means cClip only had to implement a single set of webhooks to receive events from all three providers, all in the same format. Most outgoing subscription calls route through RevenueCat, with a few edge cases requiring direct connections to Stripe or the Google Play Store.

Key Challenges

Keeping a user's subscription synchronized across platforms was one of the hardest parts. Mehta needed to prevent duplicate subscriptions and ensure status changes reflect immediately across every device. The solution stores the subscription state in Firebase Database, and clients listen for real-time updates. Write access is locked down so only verified Workers can modify the status, preventing spoofing.

File storage tracking presented another problem. B2's API doesn't expose a directory's total storage; it requires summing file values from the b2_list_file_names endpoint, one of the pricier operations. Calling that frequently would be slow and expensive. Mehta built a counter that synchronizes with B2 on each file upload or deletion, with the Worker updating it in Firebase Database. Clients receive real-time usage updates via Firebase's listener SDK.

This counter also needed to be tamper-proof. Users shouldn't be able to change their tracked storage usage, and every upload must first verify sufficient capacity. All upload requests therefore go through a Worker, which checks available storage and issues a temporary authorization only if there's enough room.

Retrospective

The serverless model proved well-suited to the project's scale. Testing new Workers features required only a quick preview or staging environment, and the platform handled production traffic without incident.

The main friction point was Stripe—the node.js SDK wasn't Workers-compatible during development. Mehta worked around it by hitting Stripe's REST endpoints directly with fetch, which worked without issues. (Stripe later shipped a Workers-compatible SDK.)

Mehta's roadmap includes rebuilding cClip Direct, the peer-to-peer file transfer protocol, with Workers managing the signaling and handshake. He also plans to move real-time communication from Firebase to Durable Objects and WebSockets, and intends to evaluate Cloudflare's R2 storage when it becomes available.