Infrastructure · 7 min read
How we built an RBAC microservice for ecommerce authentication
Inside our RBAC microservice for ecommerce: a role-based access control API with Google OAuth, JWT sessions, and Redis rate limiting, deployed serverless.
Why do internal tools end up with five different logins?
Because login is the part everyone puts off. A large furniture retailer we work with runs its operation on a growing stack of internal tools: a catalog health dashboard, an order tracking console, vendor feed pipelines, and a handful of manual harvest utilities. Each tool had grown its own idea of security. One sat behind a shared password kept in a spreadsheet. Another trusted a list of approved office IP addresses, which broke every time someone worked from home. A third had no login at all because it was "internal only."
None of this is unusual. Internal tools pile up faster than anyone plans for, and the login is the first thing deferred and the last thing revisited. The failure mode is not a dramatic breach. It is quieter than that: no consistent answer to who a user is, no way to give the warehouse lead read access without also handing over admin rights, no record of who changed what.
Staff turnover made it worse. Every departure meant changing a shared password and hoping you found all the places it was pasted.
What does an RBAC microservice actually do?
It owns identity, roles and session passes for the whole platform, so no other tool has to invent its own login. We consolidated all of it behind a single ecommerce authentication service, services/auth-service, and in practice that RBAC microservice does three jobs:
- Signs people in with Google OAuth, restricted to the company domain.
- Hands back a signed session pass (a JWT) that says who the user is and what they are allowed to do.
- Exposes a role-based access control API that every other internal service asks instead of inventing its own login.
How do you deploy an RBAC microservice on AWS Lambda?
As a small Python (FastAPI) app packaged to run on AWS Lambda behind API Gateway, Amazon's front door for APIs, with a thin adapter called Mangum connecting the two. The entire request path fits in one sentence: the gateway forwards every request to a single 256 MB function, the app routes it, and a PostgreSQL database holds the data.
Serverless was a deliberate choice for this workload. An authentication service has bursty traffic: a wave of logins at nine in the morning, a steady drip of token checks all day, near silence overnight.
Paying per request fits that shape exactly, and there is no always-on server to patch, harden, and babysit.
How do you add Google OAuth sign-in to internal tools?
With one endpoint that checks Google's proof of sign-in, then issues your own session pass. Our login flow lives at POST /auth/google. The tool posts the token Google gave it after sign-in; the service confirms it is genuine using Google's public keys and rejects any account outside the company email domain. If it checks out, the service looks the user up in auth_users and issues a signed session pass (a JWT) good for 24 hours, stamped with a secret key pulled from AWS Secrets Manager, or from local settings when a developer is working offline.
One detail worth copying: if that signing secret is not configured, the service refuses to start. An ecommerce authentication service that quietly signs tokens with a default secret is worse than one that is simply down.
How do you model roles and user permissions in the database?
With four new auth_* tables added alongside the existing schema, and zero changes to anything already there. The schema in init_auth_db.sql is deliberately additive:
- auth_users stores identity and role: admin, employee, super_admin, or client. A client_id column tags external users to their own store's data, which is how the same RBAC microservice serves internal staff and client-facing logins at once.
- auth_user_permissions maps users to the manufacturer tabs (A through J) they may open, with a granted_by column recording who approved it. This is the part a flat role cannot express: two employees with the same role can still see different vendor catalogs.
- auth_sessions keeps a fingerprint of every issued session pass alongside its expiry, IP address and device, so a pass can be revoked before it expires rather than trusted until it does.
- auth_audit_log is a running record that only ever grows: logins, failed logins, permission grants and revocations, role changes, each with the details attached. When someone asks "who gave this person access to vendor C," the answer is one quick lookup.
How do you rate-limit an authentication API?
With a Redis-backed sliding window at the edge, meaning the service keeps a running count of requests per client. The default is 120 requests per 60 seconds per client IP (tunable via RATE_LIMIT_REQUESTS), and it reads the real client IP from the proxy headers so the limiter counts the caller, not the load balancer in front of it. If Redis is unreachable the service falls back to counting in memory rather than dropping traffic.
On top of that, every response carries standard security headers (so browsers refuse framing, content sniffing and other tricks), and a catch-all error handler returns a generic error page while the real error goes to the logs where it belongs.
How do five internal tools share one login?
By pointing each one at the same role-based access control API instead of rebuilding login in every tool. The operations dashboard signs in through this service, and its order tracking calls route through the same gateway to a dedicated Lambda, which is the same delegation pattern behind our order tracking and CRM stack. Because the API already knows who is calling and what they may see, that is how five tools ended up with one login.
What does a serverless auth service cost to run?
At tens of thousands of authenticated requests a day, pocket change. The whole ecommerce authentication service runs serverless: you pay per request to Lambda, plus a modest PostgreSQL database and a small Redis node. The shared database is the largest line item, and it was already running for the rest of the platform. There is no patching window and no certificate to renew on the app itself. The failure modes that actually matter (a Secrets Manager hiccup, Redis loss, a busy database pool) each have an explicit, tested fallback rather than a page-long runbook.
Is building your own RBAC service worth it?
Yes, because it makes everything after it cheaper. An RBAC microservice is not glamorous infrastructure, but it is the kind that makes everything else possible. A single role-based access control API means onboarding a new hire is a Google sign-in plus one role grant, not five account creations. Offboarding is one switch flipped on their account plus their sessions revoked, not a scavenger hunt through spreadsheets. Client-facing tools reuse the same ecommerce authentication service and stay limited to their own store's data, instead of growing a parallel login system. And the next time someone ships an internal tool, login is already done.
Questions this answers
What is an RBAC microservice?
A standalone service that owns identity, roles and permissions for every tool behind it. Instead of each internal app inventing its own login, they all ask the same role-based access control API, which knows who the user is and what they may see.
When should an ecommerce team build role-based access control?
Usually around the third or fourth internal tool, when shared passwords and IP allowlists stop holding up. The tell is offboarding: if a departure means rotating passwords and hunting through spreadsheets, it is time for centralized RBAC.
How do you restrict Google OAuth to a company domain?
Check the sign-in on the server. When a user signs in with Google, your service confirms the proof against Google's public keys and rejects any email outside your domain before issuing a session token. Our endpoint is POST /auth/google and it issues a signed pass (a JWT) good for 24 hours.
How do you revoke a JWT before it expires?
Keep a list of active sessions on your server. We store a fingerprint of every issued JWT with its expiry, IP and device in auth_sessions, so a token can be revoked on logout or offboarding instead of trusted until it expires.
Build vs buy: should you write your own auth service?
Build when your needs are focused: company-domain Google sign-in, roles inside a session pass and an audit log. Ours is a small FastAPI service plus four tables. Buy when you need enterprise single sign-on standards like SAML, social logins at scale or a hosted user directory you do not want to operate.
Can one RBAC service handle both staff and client-facing logins?
Yes, if every account carries a tag for the store it belongs to. Our auth_users table has a client_id column, so external users see only their own store's data while internal staff get the full toolset from the same service.
How long does it take to add auth to a new internal tool?
With a central auth service, minutes: the new tool asks the existing role-based access control API instead of building a login. Our operations dashboard signs in through it, and onboarding a new hire is a Google sign-in plus one role grant.
What does a serverless authentication service cost to run?
At tens of thousands of authenticated requests a day, the compute bill is pocket change. The database is the largest line item and was already running for the rest of the platform; Redis adds a small node for rate limiting and sessions. Talk to us if you want the same pattern.
Still running on shared passwords?
If your retail operation still runs on shared passwords and good intentions, that is fixable. Talk to us, or run our agent-readiness check to see how your stack holds up.