Member-only story
The Microservices Dilemma: Centralized API vs. Direct Database Access
Designing scalable and maintainable microservices can be tricky, especially when multiple components need to interact with the same domain. After my last conversation with Rahul, where we explored the challenges of Events or Messages in an Event Driven Architecture (captured in the blog titled “Event-Driven Notifications: A Case for Queues Over Kafka Topics” available here), we found ourselves diving into another architectural puzzle over a cup of coffee.
Rahul, who is working on a user microservice, shared a problem that had been keeping him up at night. He mentioned — in his Web based application, admins managed users via a UI, and all user data went into a database after passing business validations. Events were then emitted to Kafka for downstream consumers. But as new use cases emerged — integrating external HRIS systems and supporting bulk user provisioning via CSV — the architecture grew increasingly complex. Jobs and cron jobs were introduced to handle these scenarios, and Rahul was struggling with a crucial design decision —
Should every service (API, jobs, cron jobs) directly write to the user database, or should everything go through a central service?
As we sipped our coffee, we took a step back and analyzed the broader implications of this decision. What would be the impact on maintainability, performance, and system reliability? Would a…