Latest / The API Podcast with Fexingo: REST, GraphQL, and Modern Web APIs / How API Chaining Drains Latency And Revenue
Transcript
- Lucas: Think about the last time you booked a flight or checked into a hotel app. You tap search, and maybe three seconds later, you see results. But underneath that smooth interface, your phone is likely making four or five separate network calls to different backend services. Each one waits for the previous one to finish. This is what we call API chaining, and it is quietly killing your application's responsiveness. Luna: Right, because each service has its own network overhead, database query time, and serialization cost. So those small delays stack up linearly instead of happening in parallel. Lucas: Exactly. And here is the thing most teams miss: they optimize each individual service for speed. They get their database queries down to ten milliseconds. They cache aggressively. But if the frontend requires eight sequential calls to build a single page view, you are still looking at nearly a second of pure wait time before the user sees anything. That is unacceptable in today's market. Luna: It feels like we built these microservices to be independent, but then we accidentally created a dependency chain that forces synchronous waiting. Is there a better pattern? Lucas: There is. We need to talk about Backend For Frontend, or BFF. Instead of having the mobile app or web client make five separate calls to five different microservices, you introduce an intermediate layer. This layer knows exactly what the specific screen needs. It aggregates the data from all those downstream services and sends back a single, optimized response to the client. Luna: So the client makes one call, and the BFF handles the complexity of fetching from the hotel service, the flight service, and the pricing engine behind the scenes? Lucas: Precisely. And here is where it gets interesting for our listeners who manage engineering teams. You can run those downstream calls in parallel within the BFF. If the hotel service takes fifty milliseconds and the flight service takes sixty milliseconds, a synchronous chain takes one hundred and ten milliseconds. But if you fire them off simultaneously, you only wait for the longest one. Sixty milliseconds. That is almost half the latency gone. Luna: That is a massive difference for user experience. But does adding this BFF layer not just shift the bottleneck from the client to the server? Does it increase your infrastructure costs? Lucas: It can, if you build it poorly. But think about the alternative. Without a BFF, every new feature requirement means the frontend team asks the backend team for a new endpoint. The backend team says no, because they do not want to couple tightly to that specific UI state. So the frontend starts making more calls. The chaos grows. The BFF actually decouples the UI from the internal service mesh. Luna: I see. So the BFF acts as a translator between the rigid structure of your microservices and the fluid needs of your users. It protects the core services from becoming too specialized for individual screens. Lucas: Spot on. And let us bring in some real numbers here. At Fexingo, when we analyzed our own content delivery APIs, we found that pages with more than three levels of API chaining had a median load time of two point three seconds. Pages using a BFF pattern to aggregate those calls dropped to under one second. Two point three seconds is where bounce rates start climbing sharply. One second is where retention stays stable. Luna: Two point three seconds is a lifetime in mobile usage. That explains why our competitor apps feel so much snappier even though their data might be identical. Lucas: It is not just about speed, though. There is a bandwidth cost. Every HTTP request has headers, cookies, authentication tokens, and TCP handshakes. If you make five requests instead of one, you are sending roughly five times the protocol overhead. On a spotty mobile connection, that wasted bandwidth can cause timeouts or force the app to retry, which burns battery and data caps for the user. Luna: So we are saving money on infrastructure by reducing total requests, and we are saving money on user data plans by being efficient. It is a win-win. Lucas: It is. But I want to pause here for a moment. If this conversation about API efficiency gave you something usable for your tech stack today, consider supporting the show directly. We deliberately do not run ads on these episodes. We want the focus to stay entirely on the engineering details without any distractions. If you want to support that choice, the link is buy me a coffee dot com slash fexingo. Luna: Yeah, and honestly, keeping it ad-free lets us dig into these technical weeds without worrying about sponsor alignment. It keeps the advice honest. Lucas: Thanks for listening, or rather, thanks for supporting the independence of the signal. Let us get back to the code. So, implementing a BFF sounds simple in theory, but many teams struggle with where to host it. Do you put it in the cloud? Do you run it locally? Where does it live? Luna: That is a good question. I have seen teams try to put the BFF logic directly into the mobile app itself. That seems efficient since it removes a server hop, but isn't that risky? Lucas: It is risky for security and maintainability. If you put the aggregation logic in the client, you have to update the app every time a backend service changes its schema. You cannot hot-fix the BFF. You have to push an app update, go through the app store review process, and wait for users to upgrade. With a server-side BFF, you can change the aggregation logic instantly. No client update required. Luna: Right, versioning becomes a nightmare if the business logic lives in ten thousand different devices. Keeping it server-side gives you one source of truth for how data should be composed. Lucas: Exactly. Now, let us talk about GraphQL. Some people argue that GraphQL is just a fancy way to write a BFF. And technically, you can use GraphQL to let the client describe exactly what data it wants, and the server resolves it from multiple sources. But GraphQL introduces its own complexity around caching and over-fetching if you are not careful. Luna: I agree. GraphQL is powerful, but it shifts the complexity from the network layer to the query layer. Sometimes a simple rest based BFF that returns a flat JSON object is easier to cache and debug than a complex nested GraphQL query. Lucas: That is a fair point. Simplicity often wins. A well-designed REST endpoint that aggregates data is easier for junior developers to understand than a deeply nested GraphQL schema with resolvers scattered across files. Less cognitive load means fewer bugs. And in production, fewer bugs mean less on-call stress for your SRE team. Luna: So the recommendation is not necessarily to adopt GraphQL everywhere, but to adopt the principle of aggregation wherever the client needs multiple data points? Lucas: Correct. Use the tool that fits the problem. If you need flexible querying for a dashboard where every user looks at different metrics, GraphQL might be worth the trade-off. But for standard consumer flows like product listings or checkout pages, a straightforward BFF endpoint is usually cleaner and faster to implement. Luna: What about error handling? If one of those downstream services in the BFF fails, does the whole request fail? That would be terrible for the user experience. Lucas: This is the critical part. A good BFF implements graceful degradation. If the flight service is down, the BFF should still return the hotel data and the pricing info. It might mark the flight section as unavailable, or show a cached stale result. The key is that the rest of the page still loads. You never let a partial failure block the entire user session. Luna: So the BFF acts as a circuit breaker of sorts. It isolates failures so they do not cascade all the way back to the end user. Lucas: Yes. And you can also set timeouts per downstream call. If the hotel service takes longer than two seconds, the BFF drops that request and moves on. You do not want one slow service holding up the entire page. Prioritize the critical data first, and let the non-critical data fail silently or load asynchronously later. Luna: That asynchronous fallback is smart. Show the main content immediately, and maybe slide in the delayed data later without disrupting the interaction. It preserves the feeling of speed. Lucas: Absolutely. Perception of speed matters as much as actual speed. If the user can interact with the page while the secondary data loads, they feel like the app is responsive. If they stare at a spinner for three seconds while everything waits, they feel frustrated. Luna: It reminds me of how progressive enhancement works in web development. Give the skeleton first, then fill in the details. Same principle applies here to API composition. Lucas: It does. And this approach scales beautifully. As your company grows and you add more microservices, the BFF absorbs that complexity. The frontend team stops caring about whether there are ten services or twenty. They just ask the BFF for the data they need. It reduces cross-team friction significantly. Luna: That reduction in friction is huge. Engineering teams spend so much time arguing about who owns which endpoint. If the BFF owns the composition, the backend teams can just focus on building robust, domain-specific services without worrying about UI quirks. Lucas: Right. Domain ownership remains with the backend teams. The BFF is just a utility layer. It does not own business logic. It owns data shape. That distinction is important for clear accountability. Luna: Clear boundaries make for clearer maintenance. So, to recap for our listeners: avoid deep API chains, use a BFF to aggregate and parallelize calls, handle errors gracefully, and keep the client thin. Lucas: Spot on. And remember, the goal is not just to save milliseconds. It is to create a system that is resilient, maintainable, and fast enough that your users forget they are waiting. When the technology disappears, you have done your job well. Luna: Or at least, they are too happy scrolling to notice the lag. Either way, optimizing for that invisible speed is where the real competitive advantage lies. Lucas: I love that framing. Invisible speed. Next time you open an app and it feels instant, take a moment to appreciate the architectural decisions that made that possible. Or, if it feels sluggish, maybe you know exactly which API chain is broken. Luna: Now I will never be able to unsee the network tab in my browser inspector. Thanks for breaking this down, Lucas. Lucas: Anytime. Keep your chains short and your responses parallel.