Think from the response up.
Composable backend orchestration for Kotlin
Start with what your endpoint returns. Fetch independent data in parallel and reuse results when more than one part of the response needs them.
Mosaic works with the HTTP framework you already use.
Runtime 1.1.0 · Apache 2.0val ProductPageTile by singleTile { val product = composeAsync(SelectedProductTile) val offer = composeAsync(ProductOffersTile, source(ProductId)) val availability = composeAsync(AvailabilityTile) val reviews = composeAsync(ReviewsTile) val recommendations = composeAsync(RecommendationsTile)
ProductPage( product = product.await(), price = offer.await().price, availability = availability.await(), reviews = reviews.await(), recommendations = recommendations.await(), )}PricingDeliveryRecommendationsCustomerTileStart from what
the endpoint returns.
A product page needs a price, availability, reviews, and recommendations. Each part asks for the data it needs.
The endpoint stays small even when the graph behind it grows.
Combine backend API callsval RecommendationIdsTile by singleTile { val product = composeAsync(SelectedProductTile) val customer = composeAsync(CustomerTile) source<RecommendationService>().getRecommendations( product = product.await(), postalCode = customer.await().postalCode, )}Independent work stays independent.
composeAsync starts each branch before you await its result. Use compose when the next step needs that value.
Batch naturally.
A MultiTile puts keyed work behind one reusable dependency. Overlapping requests reuse equal keys; newly pending keys can join a batch before execution starts.
Ready work is never intentionally delayed. Exact batch boundaries depend on scheduling.
Work with MultiTileval ProductsTile by multiTile { ids: Set<String> -> source<CatalogService>().getProducts(ids)}headphones-123headphones-123 reusedcase-456 fetchedSequential calls in one Mosaic. Only the new key reaches the fetch block.
Choose bulk, per-key, or chunked fetchingYour composition
is architecture.
The optional analysis plugin turns Tile relationships into a graph. Keep the code as the model, instead of maintaining a second diagram by hand.
mosaicGraph report. Static dependencies, not runtime timing or batch boundaries.See what
actually executed.
Add Mosaic execution spans to your OpenTelemetry traces. Dependency links reveal shared producers and batch callers; cache hits create no new spans.
val applicationCanvas = canvas { tracing { openTelemetry }}Your application supplies OpenTelemetry, sampling, export, and shutdown.
Trace Tile executionTest response logic
without booting the world.
Replace dependency Tiles with fixture values and leave the real response composition running. Test inputs, failures, and virtual-time delays in isolation.
mosaicBuilder() .withMockTile(ProductsTile, products) .withMockTile(PricesTile, prices) .withMosaic { assertEquals(ProductOffersTile, ids, offers) }Inside runTest; products, prices, and expected offers are fixture values.
Measured cost.
Visible tradeoffs.
Mosaic handles orchestration you would otherwise write yourself. The published application benchmark compares it with equivalent optimized Kotlin doing the same downstream work.
For the service-backed aggregate graph at 800 RPS, Mosaic added about 115 µs of CPU/request. Both implementations had median HTTP latency of about 21.12 ms.
Read the evidence and limitations| Workload | Mosaic CPU overhead |
|---|---|
| Light / batching | +14 to +21 µs |
| Aggregate graph | +48 to +115 µs |
| Sibling coalescing | +61 to +78 µs |
| CPU-heavy | +6 to +9 µs |
Ranges show additional CPU used by Mosaic versus direct Kotlin across measured profiles and rates, using rounded paired medians. CPU cost is not HTTP latency.
Bring your HTTP framework.
The same product-page composition runs behind Spring Boot, Ktor, and Micronaut.
Keep routing and HTTP concerns in your framework. Compose the response with Mosaic.
Runnable framework examples. No published framework adapter is required.
Run an exampleBuild the response.
Compose the rest.
Add Mosaic to your Kotlin project.
Your first Tile is a few lines away.