From Monolith to Microservice: Designing a Centralized Payment System for a Growing EdTech Platform
Introduction & Context
Our team of four engineers two working on backend and two on frontend came together in late December 2024 to build and scale the core infrastructure of a growing edtech platform. At that time, the company already had two live products:
- LMS (Learning Management System) — with its own Razorpay payment logic.
- Internship Portal — also managing its own payment flow (though we aren’t deeply familiar with its implementation yet).
Both platforms ran as standalone services, each built at different times, by different team. There was no shared infrastructure especially around billing and any other thing . Payments were implemented independently, and each platform managed their own version of the Razorpay integration.
We were tasked with building CRM, a central platform where organizations could manage students and operations across all services. Around the same time, a new AI Interviewer product began development as a fourth service in the ecosystem. The technical connections between these services were minimal to none but from a product standpoint, they were all part of a larger whole.
It was clear early on that each product would eventually need payment capabilities. CRM was going live in pilot soon, and AI Interviewer would need transactional logic as well. Rather than continuing to duplicate payment logic across every new service, we started asking:
What if we built a central payment service instead?
This case study outlines how our team approached designing and building a dedicated Payment Microservice from the ground up what problems we faced, the decisions we made, and what we learned in the process.
Problem Statement
As we evaluated our ecosystem, it became clear that scale wasn’t the driving force behind a payment migration rather, the fragmented and opaque state of our existing payment implementations was. Here are the core issues we faced:
- Unknown Legacy Implementations
- Both LMS and the Internship Portal had independently built Razorpay integrations before our team arrived .
- The original developers had moved on, and documentation was minimal. We simply didn’t know exactly how payments were handled in either service.
- This “black-box” situation made it nearly impossible to troubleshoot payment failures or reconcile transactions in those apps.
2. Duplicated Payment Logic Across Four Services
- We were building CRM (with payments on the roadmap) and also launching a new AI Interviewer service that would eventually require its own transactions.
- If we left things as they were, CRM, AI Interviewer, LMS, and Internship Portal would each maintain their own Razorpay integration and their own payment database tables.
- That meant four separate codebases, four different database schemas, and four potential points of failure whenever Razorpay’s API or our business rules changed.
3. Lack of a Single Source of Truth for Financial Data
- From a product and management perspective, we wanted to know at any time “How many sales did we make on LMS? What’s pending in the Internship Portal? How many CRM users have paid?”
- Because each service stored payments in its own database and because we weren’t even fully aware of the existing implementations compiling a consolidated revenue report required stitching together multiple dashboards and manual queries.
4. Maintenance Burden and Risk of Inconsistency
- Every time we needed to update payment logic whether adding a new Razorpay feature, adjusting tax or refund calculations, or tightening security checks we would have to apply identical changes to all four codebases.
- That duplication increased the likelihood of bugs creeping in (for example, mismatched refund behavior or inconsistent webhook handling).
- It also meant more work on testing: ensuring that one service’s change didn’t break another, even though they all interacted with the same external payment provider.
5. Future Growth & Architectural Alignment
- Although our current user base wasn’t large enough to force a true “scale” problem, we knew we would eventually link all four services under a unified architecture.
- To facilitate that future state where CRM, LMS, Internship Portal, and AI Interviewer could all work together seamlessly we needed a single, modular payment component that any service could call.
- In other words, the real challenge was organizational consistency and visibility, not raw throughput.
In summary, our pain points boiled down to:
- Lack of transparency into how existing payments were implemented.
- Duplicated effort across multiple services.
- No unified reporting or easy way to get a consolidated view of transactions.
- High maintenance cost and risk of divergence between services.
These factors convinced us that, even without a massive user base, we needed a centralized Payment Microservice a single source of truth for all transactional data and logic in our product suite. In the next section, we’ll discuss how we transformed this idea into a concrete design and laid the groundwork for migration.
Solution Design & Architecture
With the problem defined multiple services each owning their own opaque payment logic, and no single source of truth for transaction data we landed on one clear solution: build a dedicated Payment Microservice. This service would be the only component responsible for communicating with Razorpay, persisting all transactions, and exposing a simple, consistent API to any platform that needed to accept payments. Below is how we designed and architected this new service.
3.1 Why a Separate Payment Microservice, and Why Now?
- Centralized Logic & Data
We wanted one place to handle everything around payments authorization, capturing, verification, webhook handling, and record-keeping. By centralizing, we avoid having four different codebases re-implement Razorpay integration, and we have a single database where all transactions live. - Timing & Team Readiness
Both CRM and AI Interviewer were still under active development, so building the Payment Microservice in parallel meant we could simply point their payment flows at this new service as soon as the endpoints were available. Had we waited until later, we would have duplicated work (each new service writing its own integration) and then needed a costly migration. - Rejected Alternative
An alternative approach considered was to delay building the payment service and instead implement payment logic separately within each system. However, this option was rejected due to: - The significant duplication of effort involved.
- Increased complexity in consolidating payment records later.
- Manpower limitations, as it would require parallel development in multiple systems.
By building a centralized payment service now, we eliminate future overhead and maintain a clean separation of concerns.
Implementation Summary
- Tech Stack:
- Backend: TypeScript + Express.js
- Database: PostgreSQL
- Service Design: I was solely responsible for designing and implementing the payment service.
Database Schema
- Payment Table: Stores records of every payment made.
- Fields include:
- userId (as primary key for cross-service identity)
- platform (source of the payment request)
- orderId
- purpose (why the payment was made)
- eventDetails (if payment is related to an event)
- Webhook Table:
- Captures data sent via webhook from the payment gateway .
- Enables us to track asynchronous payment events like success, failure, or refund.
- Minimalist Approach:
- The payment service only stores the core transaction metadata (who paid, for what, from where).
- Each individual service (CRM, AI Interviewer) is responsible for handling the domain-specific logic post-payment via REST communication.
Communication
- All services communicate via REST APIs.
- We do not use a formal API spec like OpenAPI/Swagger due to shared language conventions and team familiarity.
Security Measures
- Requests to fetch or verify payment details must include a unique custom header token for authorization.
- Webhook events are verified using signature headers to ensure they are authentic and untampered.
- All endpoints are protected behind middleware validation.
What We Included and What We Left Out
Included
- Payment Capture & Verification: Any service calls /initiate to start a Razorpay order and /verify to mark it paid.
- Webhook Storage & Processing: Raw logs of every Razorpay event, so we never lose data if there’s a mismatch.
- Platform Tagging: Every payment stores which platform originated it (LMS, CRM, AI Interviewer, Internship), so reporting is trivial.
- Basic Security Measures: Internal JWT-based tokens and a custom X-Platform-Token header to prevent unauthorized calls.
Left Out (for Simplicity at Launch)
- Multi-Currency Support
- All payments are currently in INR. If we needed USD or EUR later, we’d add a currency field (we created the table anticipating this, but have not implemented any currency-conversion logic).
2. Third-Party Payment Providers
- We exclusively integrated with Razorpay. We did not build abstractions to plug in Stripe or Paytm. If that requirement arises, we’d create a provider interface layer.
3. Advanced Retry & Queueing
- For simplicity, Verify calls and webhook processing are handled in a synchronous request. We do log failed webhook processing in the Webhook table but do not yet have a background worker to retry unprocessed events.
4. Rich Refund / Chargeback Logic
- We only record “refunded” status but do not track refund IDs or partial refund histories in detail. That will be a separate enhancement
5. Subscription / Recurring Payments
- Our initial scope was single, one-time transactions. If we later offer subscriptions, we’ll extend the schema to store subscriptionId, billing cycles, etc.
By consciously omitting non-critical features at launch, we kept the service lean focused on our highest-value use case (simple, reliable one-off payments) without over-engineering.
Future Considerations :
- Message Queue for Asynchronous Processing
- Right now, webhook processing is synchronous. In a future version, we’ll push incoming webhooks to a queue and have a worker process them, enabling guaranteed retry logic and backpressure handling.
2. Support for Multiple Payment Gateways
- If we ever need Stripe or Paytm, we’d factor out a “Payment Provider” interface and inject a provider-specific implementation.
- The new service was built with this specific thing in mind . because we are planning to use multiple payment gateways in future
3. Subscription & Invoice Generation
- Our initial scope was one-off payments. Subscription billing, invoice PDF generation, and recurring logic will be separate features later.
4. Role-Based Access & Admin Panel
- We didn’t build an admin UI for refunds or manual adjustments. For now, team members run SQL queries against the Payment table. An admin dashboard is a planned enhancement.
5.Multi-Tenancy / Tenant Isolation
- If we onboard organizations with their own sub-accounts, we may need to add a tenantId column and enforce row-level security in Postgres. For today’s single-tenant use case, we left that out.
- As we are a white labelling solution offering SAAS we have immediate plan to build this feature but for staters . we have not included it.
Summary of the Design
By building a lean Payment Microservice focused strictly on capturing, verifying, and storing payments we achieved:
- Single Source of Truth for all transactions across LMS, Internship Portal, CRM, and AI Interviewer.
- Reduced Duplication: Only one codebase (and one database) touches Razorpay.
- Clear Separation of Concerns: Business logic (what happens after a payment) remains in the calling service; payment logic is isolated.
- Easier Maintenance & Reporting: Any change to payment flows or Razorpay’s API is implemented once, and reports can pull from a single Payment table.
Data Flow & Separation of Concerns
- Monolithic vs. Microservice Roles
- Previously, each service (e.g., LMS) managed Razorpay orders, signature verification, and status updates.
- Now, only the Payment Microservice talks to Razorpay.
- Business logic what happens after a payment is “paid” remains in the calling service. For example:
- CRM picks up a “payment.paid” event via its own internal service-to-service call (or a message queue in the future) and creates a new “Course Enrollment” record.
- AI Interviewer, upon successful payment, unlocks a new “Mock Interview” session for the user.
- How a Typical Payment Flow Works
- User Action (e.g., “Upgrade to Premium” on CRM frontend)
- Service Backend calls POST /payments/initiate with its internal orderId, userId, and amount.
- Payment Microservice creates a new row in Payment, calls Razorpay to get an razorpayPaymentId, updates the row, and returns the ID.
- Service Frontend uses that razorpayPaymentId to render Razorpay’s checkout widget.
- User Completes Payment in Razorpay’s modal → Razorpay sends a webhook to /webhooks/razorpay.
- Payment Microservice persists the webhook in Webhook table, verifies the signature, updates Payment.status to paid.
- Payment Microservice responds 200 OK to Razorpay and optionally publishes an internal event (e.g., on a message broker).
- Service either polls GET /payments/:paymentId or listens on the event bus to know when the status is paid, then applies business logic (e.g., enroll the user).
This separation means the Payment Microservice does not enforce business rules (e.g., “unlock lesson X”). It focuses strictly on “Did the money transfer, and can we trust that transaction?”

Learnings & Reflections
This project was my first time designing and building a microservice end to end, and the learnings were immense.
When we hear the word “microservice,” it often carries this grand impression like we’re going to architect something massive and enterprise-grade. But the truth is, the “why” behind a microservice always depends on the context of the organization. In our case, we weren’t dealing with massive scale or traffic. What we were facing was fragmentation multiple services, disconnected payment systems, and no unified way to track what was being sold, where, and to whom.
That was our real problem not scale, but visibility and future extensibility.
We didn’t set out to build a perfect, bulletproof payment system from day one. The priority was to move fast we had about five days to get this working and integrated with CRM and AI Interviewer, which were themselves still in development. So the goal was simple: build only what is necessary, and abstract the rest.
What I Learned
- Microservices aren’t always about “doing something big.” Sometimes, it’s just about solving the right problem at the right time in the simplest possible way.
- I learned how to design a schema tailored to immediate needs something minimal but extensible. Instead of over-engineering, I focused on the essential: who paid, for what, from where.
- I saw firsthand how valuable it is to build clean, self-contained logic that can scale later when the product does.
- Ownership matters building this alone meant making architectural decisions quickly, trusting my judgment, and iterating fast.
- There’s a huge difference between understanding microservices in theory and actually implementing them in a messy, real-world environment with legacy systems, unclear ownership, and evolving products.
We know this service will evolve. As our architecture moves toward more formal service-to-service communication and unified identity, this payment microservice will likely grow more robust and standardized. But for now, it serves its purpose: a simple, centralized, reliable way to track transactions across all our platforms.
And that, for me, is a win.
What’s Next
Now that the core payment microservice is in place and integrated with our CRM and AI Interviewer products, the next step is to extend its reach across our entire platform ecosystem.
We currently have four distinct services LMS, Internship Portal, CRM, and the AI Interviewer all serving different purposes but forming a single product ecosystem. Over time, we aim to connect them technically, not just functionally. This means:
- Moving toward a more centralized architecture,
- Standardizing how services communicate with each other,
- And making our payment system a single source of truth for all transaction-related data.
In the future, we may:
- Switch from REST to more formal inter-service communication protocols,
- Implement shared authentication/authorization layers .
- Add role-based access to payment data,
- Or even expose a self-service dashboard to analyze sales across services.
But we’re not rushing it. Each of these will come with their own tradeoffs and timelines. For now, the microservice is doing what it’s meant to: keeping us fast, flexible, and more in control of how payments flow through our products.
Final Thoughts
Building this system taught me that not every microservice needs to be “enterprise-grade” to be valuable. What matters more is timing, clarity, and simplicity. We solved a very real problem in a short amount of time, and laid the foundation for cleaner, more connected systems in the future.
This wasn’t about reinventing payments it was about making them manageable, traceable, and consistent across products that are only going to grow more integrated over time.
If you’re at a startup or small team thinking about building microservices: don’t be afraid to start small, move fast, and build only what’s necessary. The scale and complexity will come your architecture should be ready, but not overbuilt.