Back to articles
How-ToTools

What Happens When One Parallel Call Fails? Structured Concurrency in Scala

via Dev.toAranaDeDoros

When building backend systems, we often fan out to multiple services in parallel: Price providers Recommendation engines Search indexes Payment gateways The real question isn't "How do I run these in parallel?" It's: What happens if one fails? What happens if one times out? Do retries leak work? Can I keep partial results? I explored this while building a small price aggregation simulator in Scala 3 using Cats Effect . The scenario The setup was simple: Multiple providers Each returns a price We call them in parallel We aggregate the results But the interesting part wasn't parallelism. It was failure semantics. The Core Abstraction trait PriceProvider [ F [ _ ]] : def name : ProviderName def fetchPrice ( productId : ProductId ) : F [ Price ] Providers may fail. One specific failure is modeled explicitly: sealed trait ProviderError extends Throwable final case class TimeOutError ( provider : String , time : LocalDateTime ) extends ProviderError ( s "$provider timed out" , time ) Timeout

Continue reading on Dev.to

Opens in a new tab

Read Full Article
1 views

Related Articles