This paper presents a reliable architecture for the IoT considering multiple levels: edge, fog and cloud. This architecture can help to reduce latency and improve resiliency of IoT applications. The platform is based on a set of containerised components replicated at different levels. Fault tolerance mechanisms are provided by means of replication, the Apache Kafka framework and shadow devices. Apache Kafka is used to distribute messages along the multiple levels. Shadow devices include device states, and they can be used to avoid device interruptions using physical replication and state restoration. The architecture is also protocol-agnostic, allowing the use of different adaptors for the most common IoT protocols. A mission-critical use case is presented where this architecture can be applied. Finally, an evaluation has been carried out in order to test the feasibility of the fog infrastructure.