The paper is devoted to the problem of erasure coding in distributed storage. We consider a model of storage that assumes that nodes are organized into equally sized groups, called racks, that within each group the nodes can communicate freely without taxing the system bandwidth, and that the only information transmission that counts is the one between the racks. This assumption implies that the nodes within each of the racks can collaborate before providing information to the failed node. The main emphasis of the paper is on code construction for this storage model. We present an explicit family of MDS array codes that support recovery of a single failed node from any number of helper racks using the minimum possible amount of inter-rack communication (such codes are said to provide optimal repair). The codes are constructed over finite fields of size comparable to the code length.We also derive a bound on the number of symbols accessed at helper nodes for the purposes of repair, and construct a code family that approaches this bound, while still maintaining the optimal repair property.Finally, we present a construction of scalar Reed-Solomon codes that support optimal repair for the rackoriented storage model.The problems of centralized and cooperative repair have been addressed in multiple recent papers, and there are explicit constructions of optimal-repair regenerating codes that cover the entire range of admissible parameters, require small-size ground alphabet compared to the length n of the encoding block, and attain the smallest possible repair bandwidth [16], [23], [28], [19], [27], [30], [13] (more references are given in a recent survey [2]). The availability of optimal constructions has motivated a shift of attention toward studying data recovery not only under communication, but also connectivity constraints, in other words, storage models in which communication cost between nodes differs depending on their location in the storage cluster. One of the simple extensions from the basic setting of homogeneous storage suggests that the nodes are joined into several groups (clusters), and repair of a node can be based on information from both the nodes within its own group and from nodes in the other groups. This permits to differentiate between communication within the cluster and the inter-cluster downloads, and the natural assumption is that the former is easier (contributes less to the repair bandwidth) than the latter.Erasure coding for clustered architectures was introduced several years ago and affords several variations. One of the first questions analyzed for heterogeneous storage models was related to repair under the condition that the system contains a group of nodes, downloading information from which contributes more to the repair bandwidth than downloading the same amount of information from the other nodes [1]. Later works [6], [14] observed that a more realistic version of non-homogeneous storage should assume that the cost of downloading information depends on the relative location of th...