0
0
Microservicessystem_design~10 mins

Backend for Frontend (BFF) pattern in Microservices - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - Backend for Frontend (BFF) pattern
Growth Table: Backend for Frontend (BFF) Pattern
UsersRequests per SecondBFF InstancesMicroservices LoadData VolumeNetwork Traffic
100~10-501 small instanceLow, direct callsSmallLow
10,000~1,000-5,0002-5 instancesModerate, some cachingModerateModerate
1,000,000~100,00020-50 instances with load balancerHigh, caching + async callsLargeHigh
100,000,000~10,000,000+100+ instances, autoscalingVery high, sharded microservicesVery large, distributed storageVery high, CDN + edge caching
First Bottleneck

At small scale, the BFF server CPU and memory become the first bottleneck because it handles aggregating multiple microservice calls per user request. As users grow, the database and microservices behind the BFF start to strain due to increased query volume and data processing.

Scaling Solutions
  • Horizontal scaling: Add more BFF instances behind a load balancer to handle more concurrent users.
  • Caching: Use caching at the BFF layer to reduce repeated calls to microservices and databases.
  • Asynchronous calls: BFF can batch or parallelize microservice calls to reduce latency.
  • Microservice scaling: Scale microservices independently with replicas and sharding for data-heavy services.
  • CDN and edge caching: Offload static or semi-static content closer to users to reduce BFF load.
  • API Gateway: Use an API gateway to route and secure requests before reaching BFF.
Back-of-Envelope Cost Analysis

Assuming 1 million users generating 100,000 requests per second:

  • BFF instances: ~20-50 servers (each handles ~2000-5000 req/sec)
  • Microservices: scaled to handle 100,000 QPS total, possibly with read replicas and caching
  • Database: needs to support tens of thousands QPS, may require sharding and replicas
  • Network bandwidth: 1 Gbps = 125 MB/s, estimate average request size to calculate total bandwidth
  • Storage: depends on data retention, logs, and caching layers
Interview Tip

Start by explaining the role of BFF as a tailored backend for each frontend type. Discuss how it reduces frontend complexity by aggregating microservice calls. Then analyze scaling by identifying bottlenecks at BFF and microservices. Propose solutions like horizontal scaling, caching, and asynchronous calls. Always connect scaling steps to real user load and system limits.

Self Check

Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?

Answer: Add read replicas and implement caching to reduce direct database load before scaling vertically or sharding.

Key Result
The BFF pattern scales by horizontally adding instances and caching to handle increased user requests, but the first bottleneck is usually the BFF server CPU and memory due to request aggregation. Scaling microservices and databases with replicas and sharding follows as traffic grows.