REST BFFs provide simplicity and excellent CDN edge caching. GraphQL provides unmatched flexibility for federated multi-team microservices. tRPC offers zero-build type safety across TypeScript full-stack monorepos.
src/server/routers/mobileBffRouter.ts (typescript)
import { router, publicProcedure } from '../trpc';
import { z } from 'zod';
import { userService, orderService } from '../microservices';
export const mobileBffRouter = router({
getHomeScreenData: publicProcedure
.input(z.object({ tenantId: z.string().uuid() }))
.query(async ({ input }) => {
// Parallel internal microservice orchestration
const [userProfile, recentOrders] = await Promise.all([
userService.getUserSummary(input.tenantId),
orderService.getRecentOrders(input.tenantId, { limit: 5 })
]);
// Return ONLY the minimal tailored payload required for mobile UI
return {
userName: userProfile.displayName,
avatarUrl: userProfile.thumbnail,
unreadAlertsCount: userProfile.notifications.filter(n => !n.read).length,
orders: recentOrders.map(o => ({
id: o.id,
total: o.formattedTotal,
status: o.status
}))
};
})
});