---
title: "Delegating tasks to Fly Machines"
description: "Resource-intensive web tasks such as resizing high-resolution images can require substantially more memory or CPU than ordinary request handling, making an always-powerful web server inefficient. The article presents a framework- and language-agnostic delegation pattern using Fly Machines, the private network, and two process groups that run the same application with different Machine specifications. A Next.js route calls a wrapper that executes the task when FLY_PROCESS_GROUP is worker; otherwise, it sends a POST request to the identical endpoint through the worker’s internal hostname, returning the worker’s response. The example uses a lighter web group and a performance-4x worker group, with local development using separate ports and production routing over .internal addresses; the author calls the implementation naïve and suggests queues and worker timeouts to improve resilience and control worker availability."
---

# Delegating tasks to Fly Machines

[Fly.io](https://yomu.fyi/company/fly-io) · Feb 1, 2024

**Type:** Tutorial

## Summary

Resource-intensive web tasks such as resizing high-resolution images can require substantially more memory or CPU than ordinary request handling, making an always-powerful web server inefficient. The article presents a framework- and language-agnostic delegation pattern using Fly Machines, the private network, and two process groups that run the same application with different Machine specifications. A Next.js route calls a wrapper that executes the task when FLY\_PROCESS\_GROUP is worker; otherwise, it sends a POST request to the identical endpoint through the worker’s internal hostname, returning the worker’s response. The example uses a lighter web group and a performance-4x worker group, with local development using separate ports and production routing over .internal addresses; the author calls the implementation naïve and suggests queues and worker timeouts to improve resilience and control worker availability.

## Context

Web applications may have occasional tasks, such as resizing images, that demand substantially more memory or CPU than ordinary request handling. Keeping that capacity available for every web request can be costly when the resource-intensive work is infrequent.

## Approach / What changed

Run the application in two process groups: a web group on lighter Machines and an internal worker group on more powerful Machines. A wrapper executes the task directly when running on the worker; otherwise, it forwards a POST request to the same endpoint using the worker’s Fly.io private-network hostname and returns the response.

## Takeaways

- The delegation wrapper checks FLY\_PROCESS\_GROUP to avoid forwarding when the request has already reached a worker.
- Production requests reach the worker through a .internal hostname, while local development uses separate processes on ports 3000 and 3001.
- The implementation is described as naïve; a queue could improve resilience, and timeouts could start or stop worker Machines as needed.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Fly Machines](https://yomu.fyi/topic/fly-machines)

- Source: [Fly.io](https://fly.io/blog/delegate-tasks-to-fly-machines)
- Source URL: https://fly.io/blog/delegate-tasks-to-fly-machines
- Ingested by Yomu: 2026-09-02T11:58:06.705Z

[Read original post](https://fly.io/blog/delegate-tasks-to-fly-machines)
