I'm working on an application which has a feature of syncing records between two environments. For example, a record A is created in environment A. After a user verifies it, the user can use the sync feature to transfer the record from environment A to B. The solution has been implemented using Django API and requests module. The environment file consists of the two variables, currEnv and deployEnv. Based on their values in each environment, the records would either be sent to another environment or stored in the database.
Sample code:
import requests;
class SyncRecord():
def post(self,request):
if env.currEnv!=env.deployEnv:
requests.post('http://www.example.com',json.loads(request.POST))
else:
Model.save(request.POST)
This is currently working, but I was looking for other ways to do it. I have considered using queuing systems like Kafka and SNS, but couldn't apply to my service as there is neither a producer nor a consumer. The current solution is taking a lot of time since it needs to transfer from one environment to another and pass through different conditions.
What changes could be done to improve my API?