How to set-up failover in Postgres 9.6? I have two postgres server with a master-slave architecture, the slave is replicating the DB from the master.

In case the master goes down, the slave takes over and becomes the master.

Now, the slave has some updated data, which I want to replicate to the master, once it boots back up. How do I achieve that?
Be careful with your terminology. Your former slave is now the master.

If you have identical hardware, then there's no need to "switch back".

Regardless, you will need a new slave. You can use the former master for this; either reinitialise it in the same way you created the slave in the first place (probably using pg_basebackup), or use a tool such as pg_rewind or rsync to synchronise them. And then enable streaming replication.

If you want to "switch back", you will need to go through all the above again. That's why I run my slaves on identical hardware so I have no need to "switch back" -- I just setup a new slave (usually reusing the former master).