Dart Backend Practices at Xianyu: Glue Layer Development
Xianyu’s tech team adopted Dart for a backend glue layer that bridges frontend Flutter clients and Java domain services, leveraging Dart’s familiar syntax, strong async/await support, isolates for rapid hot‑replaceable development, and parallel Future.wait calls to achieve high‑performance, low‑latency APIs with fast deployment.
This article describes how the Xianyu tech team adopted Dart as the language for the backend “glue layer” that coordinates between frontend clients and Java‑based domain services.
The team chose Dart because its syntax is familiar to Java/Python/JS developers, it offers strong asynchronous support (Future, async/await), and it enables a unified language across frontend (Flutter) and backend, allowing frontend engineers to write backend code.
Dart’s asynchronous model lets IO‑heavy glue‑layer code be written in a near‑synchronous style while achieving the performance benefits of true async, reducing overall response time by waiting for multiple IO calls in parallel.
To improve development efficiency, the team built an isolated development environment using Dart isolates, giving each engineer a unique, hot‑replaceable sandbox that deploys changes in seconds instead of minutes.
The architecture separates stable domain services (implemented in Java) from the fast‑changing glue layer (Dart). The glue layer fetches data from Java services via HSF, processes and assembles it, and exposes the result as MTOP HTTP endpoints for the client.
Sample code shows a Java synchronous method versus a Dart async version that uses Future.wait to parallelize two service calls, illustrating the clarity and performance gain.
ItemDetailDO queryItemDetail(Long itemId) { ItemDetailDO data = new ItemDetailDO(); data.setBrowseCount(IdleItemBrowseService.count(itemId)); data.setFavorCount(IdleItemFavorService.count(itemId)); return data; }
Future queryItemDetail(int itemId) async { var data = ItemDetailDO(); await Future.wait([ IdleItemBrowseService.count(itemId).then((count) => data.browseCount = count), IdleItemFavorService.count(itemId).then((count) => data.favorCount = count), ]); return data; }
In production, the Dart‑based service handles up to 400 QPS with a 99.5 % success rate, and latency matches the Java counterpart, while code changes go from concept to deployment in under two minutes.
Xianyu Technology
Official account of the Xianyu technology team
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.