Your best bet is to make a flow diagram and mark in there what you want to happen under which circumstances, after that we can figure out which options are available. For example there is the option $realip_remote_addr which I think is mappable or at the least usable in Lua.
To loadbalance a service you either need to make the service identifiable from inside the service or from the resource using the service.
To loadbalance a service you either need to make the service identifiable from inside the service or from the resource using the service.