I Built a Free AI Background Remover Using Cloudflare Workers + D1 I spent my weekend building an AI background remover website, with both frontend and backend deployed on Cloudflare, costing almost nothing. Here's my deโฆ
I Built a Free AI Background Remover Using Cloudflare Workers + D1 I spent my weekend building an AI background remover website, with both frontend and backend deployed on Cloudflare, costing almost nothing. Here's my development journey and some lessons learned. ๐ Project URL ๐ง Tech Stack Frontend: Static HTML + JavaScript (Cloudflare Pages) Backend: Cloudflare Workers Database: Cloudflare D1 AI Background Removal: Remove.bg API Payment: PayPal ๐ Features 1. Free to Use: 3 free uses per day, no login required 2. Google Login: Cross-device sync after login 3. Credit Packs: Purchase credits via PayPal 4. Membership: Monthly/Yearly unlimited plans ๐ก Key Highlights 1. Benefits of D1 Database Previously I used localStorage, so users would lose their data when switching devices. After switching to D1, once a user logs in, their credits and membership sync across all devices. sql User table structure CREATE TABLE users ( id INTEGER PRIMARY KEY, googleid TEXT UNIQUE, email TEXT, credits INTEGER DEFAULT 0, membership TEXT, membershipexpire TEXT, totalused INTEGER DEFAULT 0 ); 2. Interesting Uses of Workers Workers aren't just for APIs - they can also serve HTML pages directly. One Worker handles all routes: javascript // Home page if (path === '/') { return new Response(HOMEPAGE, { headers: { 'Content-Type': 'text/html' } }) } // Pricing page if (path === '/pro') { return new Response(PROPAGE, {...}) } // API endpoint if (path === '/purchase' && method === 'POST') { return handlePurchase(request, env) } 3. PayPal Integration Lessons Sandbox and production have different API addresses, and sandbox testing sometimes has weird CORS issues. The final solution was to provide a manual payment confirmation as a fallback, in case the automatic flow fails after user pays. ๐ Cost Estimate | Service | Free Tier | Overage | |---------|-----------|---------| | Workers | 100,000 req/day | $0.50/million | | D1 | 5GB storage | $1/GB/month | | Pages | 500MB | Free | | Remove.bg | - | $0.07/image | Currently with a few hundred visits per day, everything is within the free tier. ๐ Future Plans [ ] Add more AI features (background replacement, resize) [ ] Batch processing support [ ] Open API for developers ๐ค Reflection This project made me rethink Cloudflare's product capabilities. The Workers + D1 + Pages combo is amazing for small to medium web applications - easy deployment, global CDN, and extremely low cost. If you have similar ideas, try this stack! Feel free to ask questions in the comments! Feel free to try and leave your feedback in the comments!
Discuss this product