How do you handle partial failures and loading states in React with a microservices backend?

Topic: microservices, React Side. Level: Intermediate.

Answer

Because downstream services fail independently, a page may have some sections load and others error. Design the UI for **graceful degradation**: render each region independently, show per-section skeletons/errors (not one all-or-nothing spinner), and use error boundaries plus React Query's `retry`/`isError` to recover or show fallbacks. This mirrors backend resilience on the client. ```jsx function ProductPage({ id }) { const product = useQuery({ queryKey: ['product', id], queryFn: () => getProduct(id) }) const reviews = useQuery({ queryKey: ['reviews', id], queryFn: () => getReviews(id), retry: 2 }) if (product.isLoading) return <Skeleton /> if (product.isError) return <Error retry={product.refetch} /> // critical section return ( <> <ProductInfo data={product.data} /> {reviews.isError // optional section degrades, page still renders ? <Notice>Reviews unavailable right now</Notice> : <Reviews data={reviews.data} />} </> ) } ```