Galaxy formation is a complex, hierarchical, highly non-linear process, which involves gravitational collapse of dark matter and baryons, supersonic, highly compressible and turbulent flows of gas, star formation, stellar feedback, as well as heating, cooling, and chemical processes. All of these processes appear to be critically important in shaping properties of galaxies. At the same time, despite the apparent complexity of these processes and the ways they interact, observed properties of galaxies exhibit a number of striking regularities, such as tight correlations between galaxy sizes, masses, luminosities, and internal velocities and surprisingly tight correlations between properties of stars and gas in galaxies and the mass and extent of their parent halos dominated by dark matter. Existence of such correlations indicates that powerful processes operate to bring order out of chaos. In this talk I will discuss some insights based on the recent work aimed to understand this aspect of galaxy formation, focusing on some specific issues in how mass of galaxies and their host dark matter halos is assembled and in how thermodynamics processes of diffuse gas, star formation, and stellar feedback conspire to produce galaxies quite close to observed systems.