Building SaaS With Rails & Next.js: Our Technical Stack and Why We Chose It
When we set out to build ClickBrat, we had a clear set of requirements: the platform needed to handle real-time AI conversations, process payments, manage scheduling across time zones, send thousands of automated messages daily, and provide a fast, modern dashboard for business owners. Oh, and it needed to be built quickly by a small team.
After evaluating our options, we landed on a stack that might surprise some people: Ruby on Rails for the backend API and business logic, and Next.js with React for the frontend. Here's why this combination works exceptionally well for a B2B SaaS platform, and some lessons learned along the way.
Why Rails for the Backend
Rails gets a lot of criticism in 2024/2025 tech discourse. 'It doesn't scale.' 'It's slow.' 'It's old.' We've heard it all. But here's what Rails gives us that no other framework matches: speed of development and maintainability for a small team.
Our backend handles user authentication, subscription billing, job scheduling, invoice generation, email/SMS delivery, webhook processing from dozens of integrations, and the orchestration layer for multiple AI models. In Rails, we built all of that with two backend engineers in under six months. The ActiveRecord ORM, built-in job queuing with Sidekiq, and the massive Ruby gem ecosystem meant we spent our time on business logic, not reinventing infrastructure.
What Rails handles in our stack:
- REST API serving the Next.js frontend and mobile apps
- Background job processing (AI orchestration, message sending, invoice generation)
- Webhook ingestion from Stripe, Twilio, calendar providers, and AI model APIs
- Database management with PostgreSQL (complex queries for analytics and reporting)
- Authentication and multi-tenant isolation
- Rate limiting, audit logging, and compliance features
As for scaling, Rails handles our current load without breaking a sweat. We're processing thousands of AI interactions daily, and our p95 API response time is under 200ms. When we need to scale specific bottlenecks, we extract those into dedicated services. But the core monolith carries the vast majority of our workload efficiently.
Why Next.js for the Frontend
The frontend had two distinct requirements: a marketing site that needed to be SEO-optimized and blazing fast, and a dashboard application that needed to be interactive and real-time. Next.js handles both elegantly.
For the marketing site (what you're reading right now), we use Next.js App Router with server components. Pages are statically generated at build time, so they load instantly. The SEO metadata is generated server-side. Framer Motion handles animations without sacrificing performance because the heavy lifting happens client-side after the initial HTML is served.
For the dashboard, we use client components with React Query for data fetching, providing optimistic updates and real-time synchronization. When a new lead comes in or a payment is received, the dashboard updates immediately without polling. WebSocket connections through ActionCable on the Rails side push events to the Next.js frontend in real time.
The AI Orchestration Layer
The most interesting part of our stack is how we handle AI. We don't use a single AI model for everything. Different features use different models based on what they need.
Our AI Phone Assistant uses speech-to-text and text-to-speech models optimized for low latency. The round-trip time from a caller speaking to the AI responding needs to be under 800ms to feel natural. We achieve this with streaming transcription, a fast inference model for generating the response, and streaming text-to-speech that starts speaking before the full response is generated.
Our content generation tools (social media posts, email drafts, quote descriptions) use more capable models where latency is less critical but quality is paramount. These run as background jobs — you request a week of social posts and they're generated in parallel, ready for review within minutes.
Our data processing tools (receipt scanning, invoice parsing, lead qualification) use a combination of vision models for document understanding and small language models for extraction and classification. These are optimized for cost since they process high volumes of routine inputs.
Deployment and Infrastructure
We deploy the Rails backend on dedicated servers with Kamal (formerly MRSK), Docker containers managed by a simple deployment tool built by the Rails team. The Next.js frontend runs on Vercel for the marketing site and on our own infrastructure for the dashboard to keep everything close to the backend API.
PostgreSQL is our primary database, with Redis handling caching, job queues, and real-time pub/sub. We use S3-compatible object storage for file uploads (receipts, documents, images). The entire infrastructure runs on three servers that cost less than most startups spend on their Vercel bill alone.
Lessons Learned
Key takeaways from building our platform:
- Start with a monolith. Extract services only when you have a proven bottleneck, not a hypothetical one.
- Choose boring technology for core infrastructure. Rails and PostgreSQL are boring. They also just work, year after year.
- Use the right AI model for each task. The cheapest model that delivers acceptable quality is the right choice.
- Invest in observability early. When you're orchestrating multiple AI models, you need to know what's slow, what's failing, and what's expensive.
- Build for the user's workflow, not your architecture. Business owners don't care about your microservices. They care that the thing works.
The best technical stack is the one that lets a small team ship fast, iterate quickly, and spend their time on the problems that actually matter to customers.
What's Next
We're continuing to invest in our AI orchestration layer, particularly around model routing and automatic quality scoring. We're also building out our mobile experience with React Native, sharing components and design tokens with our Next.js frontend for consistency.
If you're a developer considering a similar stack, or a business owner curious about the technology behind the tools you use, we're always happy to chat. The best technology decisions are the ones informed by real-world constraints, not hype cycles.
Ready to Automate Your Business?
See how ClickBrat's AI tools can save you hours every week and help you convert more leads on autopilot.