title: 'Microservices & Scheduler · Techniques' description: 'Wire Dapr pub/sub, background jobs, and queue consumers inside Nael services.'

Techniques

Microservices & Scheduler

Scale beyond HTTP by leaning on the Dapr-friendly microservices module and the Bun Worker-based scheduler. Both ship decorators that feel like NestJS while embracing streaming-friendly transports.

Install modules

Add the microservices and scheduler packages to any service that needs async work. Dapr components are optional but recommended for durable pub/sub.

Install async packages
bun add @nl-framework/microservices @nl-framework/scheduler dapr-client
Dapr subscribers

Decorate a class with @Subscriber() to automatically register handlers with the Dapr sidecar. The framework handles signature validation, tracing, and poison queue retries.

vehicle.assigned
@Subscriber({  pubsubName: "fleet-events",  topic: "vehicle.assigned",})export class VehicleAssignedConsumer {  constructor(private readonly logger: LoggerService) {}  async handle(data: VehicleAssignedPayload) {    this.logger.log("vehicle.assigned", data)  }}
Scheduler decorators

Cron, interval, and timeout decorators all run on Bun Workers so they don't block the main event loop. Each job automatically receives the DI container so you can inject repositories and services.

Cache warmers
@Cron("0 */5 * * * *", { name: "warm-cache" })handleCacheWarmup() {  return this.cache.prime()}@Interval(60_000)handleMetricsPush() {  return this.metrics.flush()}

Local sidecars

Use the Dapr CLI to bootstrap pub/sub and state components locally. The microservices example already ships opinionated component YAMLs; copy them into your own repo or customize the topics.

Run sidecar
dapr run   --app-id fleet-service   --app-port 3001   --dapr-http-port 3500   --components-path ./examples/microservices/dapr   -- bun run --cwd examples/microservices dev

Operational guidance

  • Set DAPR_TRACING_ENABLED=true to feed traces into OpenTelemetry collectors.
  • Use nl doctor --checks microservices to validate ports and component files.
  • Register schedulers inside dedicated modules to simplify feature toggling.
  • When deploying to Kubernetes, use the same components/ folder referenced in the example repo.