Deep learning solutions in big data applications can benefit cloud centres and can also lead to network communication overhead. Typically, data collected from traffic are sent to the traffic management centre for analysis. However, this process can worsen the network route to the traffic management centre. A two-tier mechanism has been developed to address this issue, which performs vehicle speed estimation and traffic congestion detection for efficient traffic management. The real-time traffic video data are captured and the video frames are initially processed through a foreground extraction process, which extracts the temporarily stopped vehicles on the road by removing background pixels from the frames. The video frames are then wrapped in an up-down view to remove the influence of the observation angle. The traffic congestion is then detected accurately based on the traffic characteristics using the proposed Ensemble Random Forest-based Gradient Optimization (ERF-GO) algorithm. The generalization error occurs when learning complex features on frames is minimized using a gradient-based optimization (GO) algorithm. Finally, the learned information on traffic conditions is forwarded to the cloud and edge computing environments based on network connection speed. The efficiency of the proposed ERF-GO is investigated in terms of performance metrics, namely root mean square error, speed detection error, execution time, computational cost, accuracy, latency, workload balance, precision, recall, f-measure, and congestion detection error rate. The analytic result displays that the proposed ERF-GO algorithm attains a greater accuracy rate of about 98.65% in detecting traffic congestion which is comparably higher than state-of-the-art methods.