Industry 4.0 applications foster new business opportunities but they also pose new and challenging requirements, such as low latency communications and highly reliable systems. They enable to exploit novel wireless technologies (5G), but it would also be crucial to rely on architectures that appropriately support them. Thus, the combination of fog and cloud computing is emerging as one potential solution. It can dynamically allocate the workload depending on the specific needs of each application. Our main goal is to provide a highly reliable and dynamic architecture, which minimizes the time that an end node or user, for instance a car in a smart mobility application, spends in downloading the required data. In order to achieve this, we have developed an optimal distribution algorithm that decides, based on multiple parameters of the proposed system model, the amount of information that should be stored at, or retrieved from, each node to minimize the data download time. Our scheme exploits Network Coding (NC) as a tool for data distribution, as a key enabler of the proposed solution. We compare the performance of our proposed scheme with other alternative solutions, and the results show that there is a clear gain in terms of the download time.