Network latency when dockers communicate with each other

I have created two containers one for front end of my application and the other for back end running both of them using docker compose. In the application on one of the sections when front end makes request to the back end, then the docker is taking a lot of time to communicate. Can you please throw somelight as to why. The same section when made to run outside of docker compose is not taking a lot of time.