# Multi Data Center Apps

**URL:** https://community.traefik.io/t/multi-data-center-apps/20558
**Category:** Traefik v2
**Tags:** rest-api
**Created:** [November 23, 2023, 12:42pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558 "2023-11-23T12:42:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![murtaza](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@murtaza](https://community.traefik.io/u/murtaza)
#### Post date: [November 23, 2023, 12:42pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/1 "2023-11-23T12:42:30Z")

</div>

We have microservices running from one datacenter planning to go in active-active setup, i mean in multi-dc setup. Note no cloud is involved here and we are only looking for on-prem setup.

We need to setup as below.

LB (1.1.1.1) --\> /web (goes to 2.2.2.2 port 80 in dc1 and 3.3.3.3 port 80 in dc2 with session persistence)  
--\> /api (goes to 4.4.4.4 port 80 in dc1 and 5.5.5.5 port 80 in dc2)

Is it possible to achieve this with traefik proxy?

---

<div class="post-metadata">

### Author: ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)
#### Post date: [November 23, 2023, 2:34pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/2 "2023-11-23T14:34:52Z")

</div>

Traefik is a reverse proxy, it should be reachable through the Internet at some IP. It can then forward requests by hostname and/or path prefix to target services.

If you want to configure targets manually, this can be done with a dynamic config file, loaded in static config with `providers.file` ([doc](https://doc.traefik.io/traefik/routing/overview/#example-with-a-file-provider)).

Just set up a `router` to match the request and a `service` to forward to multiple target hosts. Forward will be round-robin or can be sticky by cookie.

---

<div class="post-metadata">

### Author: ![murtaza](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@murtaza](https://community.traefik.io/u/murtaza)
#### Post date: [November 23, 2023, 2:51pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/3 "2023-11-23T14:51:21Z")

</div>

Ok so for dc1 i will have traefik proxy and for dc2 another instance of traefik proxy. On top of this, we will have dns loadbalancer, so how should we failover service in case a service goes down in dc1. For example /web goes down in dc1. So dns load balancer should notified about /web failure, how this will work, can you please let me know your thoughts?

Because having single traefik proxy in only either of datacenter in true sense is not active active mode.

---

<div class="post-metadata">

### Author: ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)
#### Post date: [November 23, 2023, 7:54pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/4 "2023-11-23T19:54:33Z")

</div>

Check Traefik retry middleware ([link](https://doc.traefik.io/traefik/middlewares/http/retry/)).

We use a LB from the hoster, run multiple Traefik in parallel behind it, which again do LB to the target service.

---

<div class="post-metadata">

### Author: ![murtaza](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@murtaza](https://community.traefik.io/u/murtaza)
#### Post date: [November 25, 2023, 1:35pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/5 "2023-11-25T13:35:19Z")

</div>

Will this help, also when the main site is healthy will it revert the traffic to to main site automatically?

> **[Traefik Services Documentation - Traefik](https://doc.traefik.io/traefik/routing/services/#failover-service)**
>
> Learn how to configure routing and load balancing in Traefik Proxy to reach Services, which handle incoming requests. Read the technical documentation.

---

<div class="post-metadata">

### Author: ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)
#### Post date: [November 25, 2023, 1:56pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/6 "2023-11-25T13:56:59Z")

</div>

Not sure what you mean. Traefik has an `entrypoint` on the port, has a `router` to match domain/path, optionally applies `middlewares` and then uses `service` to forward the request.

---

<div class="post-metadata">

### Author: ![murtaza](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@murtaza](https://community.traefik.io/u/murtaza)
#### Post date: [November 25, 2023, 2:33pm UTC](https://community.traefik.io/t/multi-data-center-apps/20558/7 "2023-11-25T14:33:52Z")

</div>

I mean instead of using middleware that you suggested, I can directly use out of box service called failover to achieve my goal of failovering service in dc1 to dc2 until dc1 gets healed
