Modern networked systems are increasingly reconfigurable, enabling demand-aware infrastructures whose resources can be adjusted according to the workload they currently serve. Such dynamic adjustments can be exploited to improve network utilization and hence performance, by moving frequently interacting communication partners closer, e.g., collocating them in the same server or datacenter. However, dynamically changing the embedding of workloads is algorithmically challenging: communication patterns are often not known ahead of time, but must be learned. During the learning process, overheads related to unnecessary moves (i.e., re-embeddings) should be minimized. This paper studies a fundamental model which captures the tradeoff between the benefits and costs of dynamically collocating communication partners on servers, in an online manner. Our main contribution is a distributed online algorithm which is asymptotically almost optimal, i.e., almost matches the lower bound (also derived in this paper) on the competitive ratio of any (distributed or centralized) online algorithm. As an application, we show that our algorithm can be used to solve a distributed union find problem in which the sets are stored across multiple servers. applications feature much locality, which highlights the potential of such self-adjusting networked systems [29,47,11].However, leveraging such resource reconfiguration flexibilities to optimize performance, poses an algorithmic challenge. First, while collocating communication partners reduces communication cost, it also introduces a reconfiguration cost (e.g., due to virtual machine migration). Thus, an algorithm needs to strike a balance between the benefits and the cost of such reconfigurations. Second, as workloads and communication patterns are usually not known ahead of time, reconfiguration decisions need to be made in an online manner, i.e., without knowing the future. We are hence in the realm of online algorithms and competitive analysis.This paper studies the fundamental tradeoff underlying the optimization of such workload-aware reconfigurable systems. In particular, we consider the design of an online algorithm which, without prior knowledge of the workload, aims to minimize communication cost by performing a small number of moves (i.e., migrations). In a nutshell (more details will follow below), we consider a communication graph between n vertices (e.g., virtual machines) which can be perfectly partitioned among a set of servers (resp. racks or datacenters) of a given capacity. We assume that the communication patterns, which partition the communication graph, consist of n/ vertices and that once the whole communication graph was revealed, each server must contain exactly one communication pattern.The communication graph is initially unknown and revealed to the algorithm in an online manner, edge-by-edge, by an adversary who aims to maximize the cost of the given algorithm. The cost here consists of communication cost and moving cost: The algorithm incurs one unit cost if t...