In Deep Space 9, Dr. Bashir was posted to the space station as his first assignment, but he had the rank of Lieutenant Junior Grade. Why didn't he have a rank of Ensign? Was he fast-tracked?
Bashir (like his classmate Elizabeth Lense) was promoted to the rank of Lieutenant junior grade upon graduation from StarFleet in recognition for his medical training.
This is the same as in real-world militaries today.
When you join the Military, you will be commissioned as an officer. If you join during medical school, either through the the Health Services Scholarship Program, the Uniformed Services University of the Health Sciences or the Medical and Dental Student Stipend Program, you will enter the Military as a second lieutenant in the Army and Air Force, or as an ensign in the Navy. After graduation, you will advance to the rank of captain in the Army and Air Force, or lieutenant in the Navy. If you join through the Financial Assistance Program, you will serve at the rank of at least captain (Army/Air Force), or lieutenant (Navy). - Officer + Medical Training
This can also be true of enlisted individuals (such as in the US Navy). Depending on your education level you may start at a higher rank upon competition of boot camp.
- E-2 -- Authorized enlistment in, or advancement to, paygrade E2 having satisfactorily completed one academic year or 1080 classroom hours at an accredited vocational/technical school beyond high school level.
- E-3 -- Authorized enlistment in, or advancement to, paygrade E3 having satisfactorily completed two academic years or 2160 classroom hours at an accredited vocational / technical school beyond high school level.
These are two examples from the list, there are a number of things which allow an enlisted person to start at a higher rank and pay-grade, such as being an Eagle Scout, or attending a High School Miliary Academy.
Presumably in Starfleet, like real-world militaries, doctors are commissioned at a higher starting rank than other officers. This is reflective of, among other things, the fact that physicians have to put in years of additional education after college, while regular officers (whether coming out of the military academy or an ROTC program) are typically commissioned right out of college. Moreover, since doctors are, in the course of their professional duties, required to give orders to other people (who may, like military nurses, be officers themselves), it helps maintain military protocol to have the doctors start out at a rank well above O1, so they will typically outrank everyone who may be working under them.