# Add conversation persistence with load balancer (nginx, redis, found possible solution)

**URL:** <https://forum.rasa.com/t/add-conversation-persistence-with-load-balancer-nginx-redis-found-possible-solution/54569>\
**Category:** Rasa Open Source\
**Created:** [July 29, 2022, 5:04pm UTC](https://forum.rasa.com/t/add-conversation-persistence-with-load-balancer-nginx-redis-found-possible-solution/54569 "2022-07-29T17:04:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rauldpm](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@rauldpm](https://forum.rasa.com/u/rauldpm)\
**Post date:** [July 29, 2022, 5:04pm UTC](https://forum.rasa.com/t/add-conversation-persistence-with-load-balancer-nginx-redis-found-possible-solution/54569/1 "2022-07-29T17:04:56Z")

</div>

Hello everyone

I am trying to deploy multiple opensource rasa servers through a load balancer (nginx) with reverse proxy

I currently have three instances deployed on Google Cloud Engine:

- Instance 1: NGINX
- Instance 2: Server 1 (server+actions)
- Instance 3: Server 2 (server+actions)

If I use only the load balancer instance and a server, everything works fine, but when I introduce the second rasa server in the load balancer, the bot responds but not as it should, an example:

```auto
I tell it my name
i ask who I am
bot tell me that I have not told who i am yet
i ask again
bot answer me correctly.
I ask again
bot tell me that I have not told who i am yet

```

This is obviously the behavior of the load balancer, which alternates the servers, how could I make said connection permanent for x amount of time? Would this be correct?

I have read in other posts about the use of Redis but it is not clear to me how to introduce it in the deployment, would I have to install it in the load balancer and connect the servers to it, or would I have to install it in each server?

---

<div class="post-metadata">

**Author:** ![rauldpm](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@rauldpm](https://forum.rasa.com/u/rauldpm)\
**Post date:** [July 29, 2022, 11:41pm UTC](https://forum.rasa.com/t/add-conversation-persistence-with-load-balancer-nginx-redis-found-possible-solution/54569/2 "2022-07-29T23:41:56Z")

</div>

Nevermind, I just found the solution after too much forums and try-error (I always find the solution after asking, it doesn’t matter if I spend a whole day trying it before, it’s asking and hitting the nail on the head)

Architecture:

- Instance 1:

- Instance 2:

- Instance 3:

Docker-compose redis file:

```auto
version: '3.0'
services:
  redis:
    image: redis:latest
    container_name: redis
    ports:
      - 6379:6379

```

Now, each rasa server endpoint has to set this configuration:

```auto
tracker_store:
    type: redis
    url: load-balancer-ip (preferable the internal ip, where the redis container is deployed)
    port: 6379
    db: 1
    password: (yes, this is empty, no authentication will be done)

lock_store:
    type: redis
    url: load-balancer-ip (preferable the internal ip, where the redis container is deployed)
    port: 6379
    db: 0
    password:
    key_prefix: rasa

#tracker_store:
# type: sql

```

Then, when you start both rasa server, the nginx and redis containers, you can access to the redis container with:

- docker exec -it id /bin/bash

Then run:

- redis-cli

Once in redis interface, run

- select 1 (this is the tracker database)

Run:

- keys \*

Now you will see all the tracker id of the user who talked to the bot, you can see the conversation with:

- get tracker: id

In this way, although the telegram request is balanced between the servers, the database will be unified and therefore, each user will have a record of their history, allowing interactions not to be mixed

Kudos to [Rasa course, rasa training, rasa interview, docker tracker store redis service deployment of Rasa practical series](https://javamana.com/2022/116/202204260319292338.html)

Also, for bonus configuration, this is my nginx configuration (i know i can do it better)

- default.conf

```auto
#/etc/nginx/conf.d/default.conf
upstream lb {
  include servers;
}

# http access with reverse proxy
server {
  listen 80;

  # reverse proxy
  location / {
    proxy_pass http://lb;
  }
}

# https access with reverse proxy
server {
  listen 443 ssl;

  # set ssl certificates for https access
  ssl_certificate /etc/letsencrypt/live/your-ld-domain/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/your-ld-domain/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/your-ld-domain/fullchain.pem;

  # reverse proxy
  location / {
    proxy_pass http://lb;
  }
}

```

- servers file (the include reference)

```auto
server ip-1:5005;
server ip-2:5005;

```

The ssl certificates has been created with certbot and letscrypt, you will need to use a domain (aws ec2 domains does not work [Policy forbids issuing for name on Amazon EC2 domain - #4 by jsha - Server - Let's Encrypt Community Support](https://community.letsencrypt.org/t/policy-forbids-issuing-for-name-on-amazon-ec2-domain/12692/4))

It would be nice if someone can confirm this solution to mark it as Solution, as anyone has responded the thread yet

Regards, Raúl.
