I just finished building a full Instagram DM automation SaaS for a client. Think ManyChat โ but built from scratch, for the Indian market.
Let me walk you through what went into it. ๐
๐ง๐ต๐ฒ ๐ฐ๐น๐ถ๐ฒ๐ป๐'๐ ๐ฟ๐ฒ๐พ๐๐ถ๐ฟ๐ฒ๐บ๐ฒ๐ป๐๐ ๐๐ฒ๐ฟ๐ฒ ๐ฐ๐น๐ฒ๐ฎ๐ฟ:
โข Auto-DM anyone who comments a keyword on a post
โข Auto-DM story replies and mentions
โข Referral system โ PRO users earn โน24.75 for every person they refer
โข Two pricing tiers: Free (โน0) and Creator Pro (โน429/month)
โข Referred users pay only โน99 for their first month
Simple to describe. Surprisingly nuanced to build correctly.
๐ง๐ต๐ฒ ๐ฝ๐ฎ๐ฟ๐ ๐บ๐ผ๐๐ ๐ฑ๐ฒ๐๐ ๐ด๐ฒ๐ ๐๐ฟ๐ผ๐ป๐ด โ ๐๐ป๐๐๐ฎ๐ด๐ฟ๐ฎ๐บ ๐ข๐๐๐๐ต:
Instagram gives you a token that expires in 1 hour.
You must immediately exchange it for a 60-day long-lived token.
Then refresh it at day 53.
Miss any of this โ every automation silently breaks at day 60. No error. Just stopped DMs.
I built the full lifecycle: connect โ exchange โ hash + store โ auto-refresh cron โ manual refresh UI for users.
๐ง๐ต๐ฒ ๐ฝ๐ฎ๐ฟ๐ ๐๐ต๐ฎ๐ ๐ฐ๐ผ๐๐น๐ฑ'๐๐ฒ ๐ฑ๐ฎ๐บ๐ฎ๐ด๐ฒ๐ฑ ๐๐ต๐ฒ ๐ฐ๐น๐ถ๐ฒ๐ป๐'๐ ๐ฟ๐ฒ๐ฝ๐๐๐ฎ๐๐ถ๐ผ๐ป:
Meta retries webhook delivery 3 times if you don't respond fast enough.
Without a deduplication layer, a single comment triggers three identical DMs to the same person. I've seen this happen in production at other companies โ users block the account immediately.
Solution: a WebhookEvent table with a unique constraint on (provider, messageId). The second insert fails at the database level. No duplicate DMs. Ever.
๐ง๐ต๐ฒ ๐ฟ๐ฒ๐ณ๐ฒ๐ฟ๐ฟ๐ฎ๐น ๐๐๐๐๐ฒ๐บ ๐ฑ๐ฒ๐๐ฎ๐ถ๐น ๐'๐บ ๐ฝ๐ฟ๐ผ๐๐ฑ ๐ผ๐ณ:
The "first-time user only" rule for referral discounts is enforced by a @unique constraint on the referredUserId column โ not application code.
Even if there's a race condition (two requests hitting the API simultaneously), the database rejects the second insert. No double-discounts possible.
This is the difference between a system that works in testing and one that works in production.
๐๐๐น๐น ๐๐๐ฎ๐ฐ๐ธ ๐ฑ๐ฒ๐น๐ถ๐๐ฒ๐ฟ๐ฒ๐ฑ:
Next.js 14 ยท tRPC ยท TanStack Query ยท BetterAuth ยท Prisma ยท PostgreSQL ยท BullMQ ยท Redis ยท Recharts
This project reminded me why I love freelance work.
You're not building a demo. You're building something real people will use, real money will flow through, and real businesses will depend on.
That pressure makes you a better engineer.
If you're a founder, startup, or business that needs a full-stack SaaS product built with this level of attention to detail โ let's talk.
Comment below or send me a DM. Always happy to discuss your project.
hashtag#Freelancing hashtag#SoftwareDevelopment hashtag#NextJS hashtag#SystemDesign hashtag#SaaS hashtag#FullStack hashtag#TypeScript hashtag#BuildInPublic hashtag#IndianDevelopers