Whenever I download something it starts slow but gets faster overtime then stays the same whereas speed in UDP increases or decreases randomly.
So my question is, what causes TCP to get faster and why UDP is more unstable compared to TCP?
So my question is what causes TCP to get faster
Most likely that is due to TCP's slow start feature, which is designed to avoid overloading the network with too much traffic by starting out at a conservative pace, and only increasing the transfer rate once the algorithm has recognized that the network is handling the initial rate without too many dropped packets. The rate will increase until packets start being dropped, at which point the TCP layer will back off a bit, until finally it (hopefully) arrives at the fastest transfer rate that network conditions can reliably support.
why UDP is too unstable when compared to TCP?
Unlike TCP, UDP doesn't make any attempt at congestion control; that sort of thing is left entirely up to the application programmer. All UDP does is send individual UDP packets (when the calling program asks it to by calling send() or sendto()), which may or may not arrive at their destination; if they do not arrive (for whatever reason) no further action is taken by the transport layer. So any particular behavior you see with UDP packets is more an indication of how your UDP-using application was programmed, than an indication of how the UDP transport layer behaves.