---
title: Service Affinity in Scheduling and Placement
url: https://www.emergentmind.com/topics/service-affinity
type: topic
---

# Service Affinity in Scheduling and Placement

Searching arXiv for recent and foundational papers on service affinity across scheduling, microservices, serverless, and edge placement.
Service affinity denotes a class of scheduling and placement problems in which the desirability or feasibility of assigning work to a resource depends on a relation between the workload entity and the execution site. In queueing-theoretic formulations, it is the problem of dynamically assigning typed tasks to servers whose processing capabilities differ by task type so that the system is stable for all admissible loads and delays remain small near saturation [1709.08115]. In cloud-native and serverless systems, it is expressed through communication intensity, co-location and anti-affinity rules, privacy or functional tags, and hardware or location requirements that shape microservice, function, or agent placement [2509.05790] [2407.14572] [2601.02021]. The common structure is a constrained mapping problem: affinity alters the effective service rate, communication cost, feasibility region, or all three simultaneously.

## 1. Queueing-theoretic foundations

The classical service-affinity problem is a heterogeneous queueing system with servers \(M=\{1,\dots,M\}\), task types \(I=\{1,\dots,I\}\), arrival processes \(A_i(t)\), and type-server service rates \(\mu_{i,j}>0\). In the generic model summarized for GB-PANDAS, service times are non-preemptive, arbitrarily distributed with mean \(1/\mu_{i,j}\), and queue dynamics are
\[
Q_{i,j}(t+1)=Q_{i,j}(t)+A_{i,j}(t)-S_{i,j}(t).
\]
A necessary and sufficient stability condition is the existence of a decomposition \(\lambda_{i,j}\ge 0\), \(\sum_j \lambda_{i,j}=\lambda_i\), such that
\[
\sum_{i=1}^I \frac{\lambda_{i,j}}{\mu_{i,j}}<1,\qquad \forall j,
\]
which defines the capacity region \(C\) [1709.08115].

This formulation specialized naturally to data locality in large data centers. In MapReduce-style systems, a task is machine-local, rack-local, or remote depending on where its data block resides, with service parameters \(\alpha>\beta>\gamma>0\) and corresponding mean service times \(1/\alpha<1/\beta<1/\gamma\) [1705.03125]. A related large-scale service-system model assigns each job type \(j\) a primary server subset \(P_j\) and a secondary subset \(S_j=P_j^c\); primary service occurs at rate \(\mu_1\), secondary service at rate \(\mu_2\) with \(0<\mu_2<\mu_1\). The dispatcher first seeks an idle primary server, then an idle secondary server, and otherwise sends the job to the lexicographically shortest primary queue, while servers give preemptive priority to primary jobs [1812.10703].

The analytical objectives have remained stable across these variants. Throughput-optimality requires positive recurrence whenever the arrival-rate vector lies strictly inside the capacity region. Heavy-traffic optimality studies sequences \(\lambda^{(\epsilon)}\to \lambda^*\) on the boundary and asks whether the policy minimizes \(E[\text{delay}]=E[\text{time in system}]\) to first order under diffusion scaling [1709.08115]. This framing explains why affinity is not merely a locality heuristic: it is a structural modification of the service process, and hence of both stability and delay.

## 2. Formal representations of affinity

Across the literature, service affinity is represented in several mathematically distinct but structurally related ways.

| Setting | Affinity representation | Optimization target |
|---|---|---|
| Queueing and data locality | \(\mu_{i,j}\), \(\alpha_n\), primary/secondary sets | stability and delay |
| Microservice placement | \(a_{u,v}(\Delta t)\), \(w_{u,v}\), cut weights | minimum cross-domain cut |
| Serverless and cluster provisioning | \(A(t)\), \(\bar A(t)\), \(A_{ij}\), \(a_{ij}\) | latency, feasibility, node minimization |
| Edge agent placement | \(\Psi_i\subseteq\{\text{TEE},\text{Camera},\text{LiDAR},\dots\}\) | feasible low-hop embedding |

In graph-based microservice systems, affinity is an edge weight. SAGA defines five primitive metrics over a sliding window \(\Delta t\): data affinity \(d_{u,v}(\Delta t)\), coupling affinity \(c_{u,v}(\Delta t)\), privacy affinity \(p_{u,v}\), functional affinity \(f_{u,v}\), and operational affinity \(o_{u,v}\). Raw service affinity is a weighted sum
\[
a_{u,v}(\Delta t)=\sum_{i\in\{d,p,c,f,o\}} w_i\cdot a_i(u,v,\Delta t),
\]
followed by min-max normalization to obtain edge weights \(w_{u,v}\in[0,1]\) in a Service Affinity Graph \(G=(V,E,w)\) [2509.05790]. DREAMS adopts the service-affinity notion introduced in SAGA but uses a streaming-window form in which, for microservices \(m\) and \(v\), \(a_{m,v}(\Delta t)\) combines communication rate, dependency, and tunable weights \(\alpha,\beta\) that can incorporate data privacy, resource sharing, or domain-specific factors [2509.07497].

In serverless systems, affinity is often a hard logical predicate. The aAPP model associates each function tag \(t\) with an affine set \(A(t)\subseteq T\) that must already appear on the same worker and an anti-affine set \(\bar A(t)\subseteq T\) that must not appear there. A worker \(w\) is affinity-valid for function \(f\) with tag \(t\) exactly when
\[
A(t)\subseteq \{\mathrm{tag}(g)\mid g\in \mathrm{active}(w)\},
\qquad
\bar A(t)\cap \{\mathrm{tag}(g)\mid g\in \mathrm{active}(w)\}=\emptyset
\]
[2407.14572]. In shared-cluster provisioning for long-running applications, affinity is a directed restriction graph \(\mathcal A\) with parameters \(a_{ij}\in\mathbb N\), where \(a_{ij}\) is the maximum number of replicas of \(j\) that may co-locate on a node if at least one replica of \(i\) is there [2208.12738].

These formulations differ in algebraic form—service-rate matrices, graph weights, Boolean co-location predicates, hardware-label constraints—but all encode non-exchangeability. A resource is not simply “faster” or “slower” in the abstract; it is better or worse for a particular workload entity.

## 3. Affinity scheduling in data centers and service systems

The affinity-scheduling literature developed a sequence of algorithms that trade off practicality, information requirements, and optimality guarantees. Early approaches with theoretical guarantees included fluid model planning, the MaxWeight algorithm, and the generalized \(c\mu\)-rule, but these were described as impractical for data center applications because of non-realistic assumptions [1709.08115]. In MapReduce data-locality systems, the same tension appears between heuristic methods such as Delay Scheduling and Quincy, and algorithms with explicit throughput or heavy-traffic guarantees [1705.03125].

GB-PANDAS addresses the multi-level locality case with \(N\) locality levels and service-rate parameters \(\alpha_1>\alpha_2>\cdots>\alpha_N\). Each server \(m\) keeps sub-queues \(Q_m^n\), and its expected workload is
\[
W_m(t)=\sum_{n=1}^N \frac{Q_m^n(t)}{\alpha_n}.
\]
Upon arrival of a task of type \(\Lambda\), routing uses the weighted-workload rule
\[
m^*=\arg\min_{m\in M}\left\{\frac{W_m(t)}{\alpha_n}:\text{server }m\text{ is }n\text{-local to this task}\right\},
\]
and scheduling is strict priority from \(Q_m^1\) to \(Q_m^N\) [1709.08115]. Throughput optimality is proved by augmenting the state to \(Z(t)=(Q(t),\Psi(t),\eta(t))\), choosing the Lyapunov function \(V(Z)=\|W\|_2^2+\|\Psi\|_1\), and establishing a negative \(T\)-step drift:
\[
E[V(Z(t+T))-V(Z(t))\mid Z(t)=Z]\le -\theta(\|Q\|_1+\|\Psi\|_1).
\]
The proof uses a workload evolution equation, a routing lemma, a service lemma over \(T\) slots, and an age lemma [1709.08115].

The algorithmic significance lies in the assumptions it avoids. GB-PANDAS is proved throughput-optimal for arbitrary service-time distributions, whereas much previous theoretical work assumed geometric service times. In simulations on a 5,000-server cluster with 4 locality-levels, log-normal service times with \(\mu_1=1\), \(\mu_2=10/9\), \(\mu_3=5/3\), and \(\mu_4=4\), and comparisons against FCFS, JSQ-Priority, and JSQ-MaxWeight, GB-PANDAS halved the mean completion time relative to JSQ-MaxWeight under high load, with up to \(2\times\) improvement at \(\rho=0.95\) [1709.08115].

Blind GB-PANDAS removes knowledge of both arrival rates and service rates. It maintains estimates \(\widetilde\mu_{i,m}(t)\), updates them from service completions, and alternates exploitation with exploration using a monotone-decreasing \(p(t)\) satisfying \(\sum_t p(t)=\infty\). In exploitation, an arriving type-\(i\) task is routed by
\[
m^*=\arg\min_m \frac{\widetilde W_m(t)}{\widetilde \mu_{i,m}(t)},
\]
while scheduling serves the highest-priority nonempty sub-queue; exploration randomly samples servers or sub-queues so that all locality classes are observed infinitely often [1901.04047]. The resulting Markov chain \(Z(t)=(Q(t),\eta(t),\Psi(t))\) is irreducible, aperiodic, and positive-recurrent whenever \(\lambda\in\Lambda\). Experiments with three servers, three task types, Poisson arrivals, and log-normal heavy-tailed service times found that Blind GB-PANDAS remained stable up to capacity and delivered substantially lower delays in heavy traffic, often \(30\%-50\%\) better than Max-Weight or \(c\mu\)-rule with exploration [1901.04047].

Related models clarified structural phenomena that are not visible in single-rate load balancing. In the primary-secondary model, affinity coupling bounds the original non-exchangeable system by reference systems such as RA, MJSQ\((k)\), and JSQ\((k)\), yielding explicit stability conditions and performance bounds [1812.10703]. In the symmetric combinatorial model, the fluid limit exhibits two regimes: a unique all-busy fixed point for small \(d\), and bistability when \(d\ge d^*(\lambda,\mu_1,\mu_2)\), with one stable no-queueing mode, one unstable fixed point, and metastability on long time scales [1812.10703]. A different extension studies job-server affinity under uncertainty of job types and threshold-based rerouting or replication. There, full replication \((\tau=0)\) maximizes the achievable stability bound in highly unbalanced speed regimes, zero redundancy \((\tau=\infty)\) is best in nearly balanced regimes, and a suitable threshold can reduce expected latency under \(M/G/1\) approximations [2005.13353].

## 4. Graph-based service affinity in microservice systems

In microservice architectures, service affinity is often operationalized as a weighted interaction graph and solved as a partitioning problem. SAGA models the system as an undirected weighted graph \(G=(V,E,w)\), where \(V\) is the set of microservice instances, \(E=\{(u,v)\mid a_{u,v}(\Delta t)>0\}\), and \(w_{u,v}(\Delta t)\) is the normalized affinity weight [2509.05790]. Placement is then formulated as a minimum-weight \(k\)-cut: partition \(V\) into \(k\) disjoint subsets \(S_1,\dots,S_k\) so as to minimize the total weight of edges crossing partitions. An integer-programming form minimizes \(\sum_{(u,v)\in E} w_{u,v}x_{uv}\) subject to assignment, cut-consistency, and optional balance constraints [2509.05790].

SAGA uses a modified \(k\)-way Kernighan-Lin heuristic. Each two-way pass runs in \(O(n^2\log n)\) on a subset of size \(n\); recursively splitting until \(k\) subsets are obtained yields total worst-case time \(O(\lceil \log_2 k\rceil\cdot n^2\log n)\) [2509.05790]. The framework is organized as three services within Kubernetes: Cluster Monitoring Service, Affinity-based Clustering Service, and Migration Orchestration Service. In a prototype built on Microsoft eShopOnWeb with RabbitMQ and deployed on Google Kubernetes Engine with 1 control-plane and 3 worker nodes, SAGA reduced mean latency from \(31.80\) ms to \(24.36\) ms over 200 requests, a \(23.40\%\) reduction, while also tightening the latency distribution [2509.05790].

DREAMS extends the graph view to a decentralized compute-continuum setting. For each candidate migration of microservice \(m\) into cluster \(c\), it computes a Cluster Affinity Score
\[
A_c(m)=\sum_{v\in \mathcal N_c(m)} a_{m,v}(\Delta t),
\]
defines intra-domain and best inter-domain affinities,
\[
A_{\mathrm{intra}(m)}=A_{c_{\mathrm{curr}(m)}}(m),\qquad
A_{\mathrm{inter}(m)}=\max_{c\neq c_{\mathrm{curr}(m)}} A_c(m),
\]
and uses the Affinity Gain
\[
\Delta A=A_{\mathrm{inter}(m)}-A_{\mathrm{intra}(m)}
\]
as the basic migration signal [2509.07497]. The global problem is to partition the interaction graph \(G=(V,E)\) with edge weights \(w(u,v)=a_{u,v}(\Delta t)\) so as to minimize the total affinity cut across domain boundaries, subject to capacity constraints such as CPU and memory limits [2509.07497].

The distinctive feature of DREAMS is decentralized coordination. Each Local Domain Manager proposes at most one migration per leader term using a net score \(Q=\Delta A-L\), where \(L=\ell/(1+\exp(\Delta A/\gamma_{\mathrm{proposal}}))\), and proposes only if \(Q>\theta_{\mathrm{proposal}}\). Followers perform cost-benefit voting using a normalized local-impact score, a latency-change term \(\Delta \ell\), an affinity-penalty weight \(W_{\mathrm{aff}}\), and a scaled penalty \(P_{\mathrm{lat}}\), voting YES when \(P_{\mathrm{lat}}<\theta_{\mathrm{vote}}\) [2509.07497]. This exchange is embedded into a Raft cycle that tolerates \(\lfloor (N-1)/2\rfloor\) crashes and commits after a quorum of \(\lceil N/2\rceil+1\) acknowledgements. In deployments of 3–20 LDMs across Google-Cloud regions, mean registration time grew sub-linearly from approximately \(620\) ms to approximately \(1{,}800\) ms, worst-case convergence from \(556\) ms to \(3{,}121\) ms, and migration voting latency from \(642.8\) ms to \(1{,}054.1\) ms. On a 10-service graph with initial inter-domain cut weight \(630\), DREAMS converged to the offline-computed optimum of \(395\) [2509.07497].

## 5. Serverless functions and shared-cluster provisioning

In serverless systems, affinity can be imposed declaratively as a scheduling constraint rather than inferred from traffic. The aAPP extension to APP lets each tag specify blocks containing worker sets, strategies, invalidate constraints, and an affinity list mixing positive and negated tags. Scheduling evaluates blocks in order, filters candidate workers by capacity, concurrency, and the affinity predicate, then chooses a worker by `best_first` or `any`; if no block succeeds, it either fails or follows the default tag, depending on `followup` [2407.14572]. The complexity per request is linear in policy size and candidate workers, stated as \(O(\#\mathrm{blocks}\times \#\mathrm{candidates}\times (\mathrm{avg\ block\ checks}))\) [2407.14572].

A prototype integrated into Apache OpenWhisk modified the Controller’s load-balancer, added a parser for `.aapp` scripts, and maintained state tables for active functions and tag activations [2407.14572]. In an affinity-aware “divide-et-impera” scenario with two interdependent functions and co-tenant heavy functions across two geo-zones, full aAPP affinity plus anti-affinity achieved mean latency \(1547\) ms, median \(883\) ms, and 95% tail \(3041\) ms after 250 runs. The anti-affinity-only baseline had mean \(2337\) ms, median \(2381\) ms, and tail \(3476\) ms, while plain APP had mean \(8118\) ms, median \(2648\) ms, and tail \(60157\) ms; retries to read from the database were \(0\) under aAPP versus \(23\)–\(42\) in the baselines [2407.14572]. In non-affinity microbenchmarks, differences between APP and aAPP were under \(1\) ms on average, and both were under \(2\) ms relative to vanilla OpenWhisk [2407.14572].

Static analysis becomes much harder once positive affinity is admitted. The formal study of aAPP reachability shows that without affinity, reachability and co-occurrence are decidable in linear time, while full affinity and anti-affinity make reachability PSPACE-complete. A polarized fragment with only anti-affinity remains linear, whereas positive-affinity-only reachability is NP-hard and still in PSPACE [2407.14159]. This result identifies a precise trade-off between policy expressivity and analyzability.

ICPS addresses serverless workflow execution from a dynamic-scaling perspective. It predicts workflow and function concurrency with an LSTM, maps workflow-level predictions to function-level predictions by
\[
\hat c_t(f_n)=\sum_{s=1}^S \widehat{Con}^t_s\,R(f_n,K_s),
\]
sets pre-warm targets \(p_t(f_n)=\lceil \hat c_t(f_n)\rceil\), and deploys new instances using an Affinity Deployment Strategy based on invocation-frequency scores
\[
A_{ij}=\frac{1}{W}\sum_{w=1}^W \mathbf 1\{(f_i\to f_j)\in wf_w\}.
\]
Placement minimizes the penalty from cross-node invocations \(\sum_{i,j}\sum_{w\neq w'} A_{ij}d\,x_{i,w}x_{j,w'}\) subject to worker memory limits [2504.06512]. Against six baselines, ICPS reported up to \(25\%-40\%\) reduction in average workflow response time under high concurrency \((>5\times 10^5\) requests), \(30\%-50\%\) fewer cold starts, and an overall \(10\%-20\%\) improvement in \(\eta\); when inter-node latency \(d\) was \(10\)–\(15\) ms, affinity-based co-location yielded a \(20\%-35\%\) reduction in end-to-end critical-path latency [2504.06512].

Affinity also appears as a provisioning constraint in shared clusters running long-running applications. The ILP model for affinity-aware resource provisioning uses binary placement variables \(x_{irn}\), node-use variables \(y_n\), and application-presence variables \(z_{in}\), with node-count objective \(\min \sum_{n\in\mathcal N} y_n\), capacity constraints, and general co-location upper bounds
\[
\sum_{r\in \mathcal R_j} x_{jrn}\le a_{ij}z_{in}+\nu_j(1-z_{in}),\qquad \forall (i,j)\in \mathcal A,\ \forall n\in \mathcal N.
\]
Special cases encode must-together co-location and anti-affinity exactly [2208.12738]. The paper studies Application-Centric, Node-Centric, and Multi-Node heuristics, reporting, for example, \(4.5\%\) deviation with Multi-Node Spread+WFD (BS) on static 2-dimensional instances with \(|\mathcal L|=9{,}338\), and \(0.9\%\) deviation on static large-scale instances with \(|\mathcal L|=100{,}000\) [2208.12738]. The best heuristics reduced node usage by up to approximately \(7\%\) relative to naïve AC approaches or existing schedulers, corresponding to approximately \(350\) servers in a 5,000-node scenario, approximately \(1.8\) GWh/year, and approximately \(0.9\) kton \(\mathrm{CO}_2\) avoided under the stated power assumptions [2208.12738].

## 6. Hard constraints, semantic affinity, and open issues

Recent work extends service affinity beyond communication locality to explicit hardware and semantic constraints. In AgentVNE, service affinity refers to hard, often hardware- or location-based dependencies such as a Trusted Execution Environment or a camera interface. Each virtual node \(n_v\) carries required hardware attributes
\[
\Psi_{n_v}\subseteq \{\text{TEE},\text{Camera},\text{LiDAR},\dots\},
\]
and feasibility is enforced by
\[
x_{i,u}\,\mathbb I(\alpha\notin \mathcal L_u)=0
\qquad \forall i\in N^V,\ \alpha\in \Psi_i,\ u\in N^S.
\]
To bias placement toward affinity-constrained nodes, AgentVNE augments a substrate node’s resource tuple \(\boldsymbol\Omega_u\) with a virtual resource-bias vector \(\mathbf B_{\mathrm{bias}}\), then applies a dual-stream GCN-plus-Transformer encoder, a column-wise neural tensor network, supervised pre-training, and PPO fine-tuning [2601.02021]. In the reported simulations, AgentVNE reduced workflow communication latency to less than \(40\%\) of baselines and improved service acceptance rate by approximately \(5\%-10\%\) under high-load scenarios [2601.02021].

The progression from queueing models to graph partitioning, declarative policies, and semantic inference has not removed the core tensions of service affinity. One recurring issue is information and coordination overhead. GB-PANDAS requires per-server per-level queue lengths and central knowledge of \(W_m(t)\), which may incur messaging cost; proposed extensions include power-of-\(d\) sampling of workloads, join-idle-queue hybrids, and decentralized approximations [1709.08115]. DREAMS addresses coordination by decentralizing placement decisions with Raft-based consensus, but still measures voting and registration latencies explicitly [2509.07497]. Another issue is unresolved optimality: for GB-PANDAS, a full heavy-traffic proof remains open, although simulations and an informal state-space-collapse argument suggest concentration on a single dimension in the Halfin-Whitt regime and superiority over JSQ-MaxWeight except in degenerate two-level cases [1709.08115].

A further tension is that affinity can improve locality while worsening interference or verification complexity. ICPS notes that co-locating high-affinity functions can increase CPU and memory contention, and suggests extending affinity with an interference model \(I_{ij}\) [2504.06512]. The formal analysis of aAPP shows that adding general affinity elevates reachability checking from linear time to PSPACE-complete, even though anti-affinity alone remains tractable [2407.14159]. These results suggest that service affinity is not a single technique but a design axis: one chooses how much of the system’s heterogeneity, interaction structure, or governance policy to encode explicitly in placement, and then accepts the corresponding cost in state, computation, or analysis.

Within that design axis, the field has converged on a broad principle. Whether the affinity signal is a service-rate matrix, a locality level, a graph edge weight, a co-location predicate, or a hardware-label set, performance improves when the scheduler or orchestrator uses the signal directly rather than treating resources as exchangeable. The exact gain depends on the model class: throughput and heavy-traffic behavior in typed-task queues [1709.08115], cut-weight and latency in microservice graphs [2509.05790] [2509.07497], cold-start and workflow response in serverless systems [2504.06512] [2407.14572], node count and carbon impact in shared clusters [2208.12738], and feasible low-hop embedding in edge agentic AI [2601.02021].

Source: https://www.emergentmind.com/topics/service-affinity