Entropy and gravitational attraction 
Any process which is spontaneous and irreversible must involve a (positive) change in entropy of the universe

This is one condition to the spontaneity of a process that the overall universe (System + Surroundings) must experience a positive entropy change.
Going back some 4.5 billion years:


*

*The sun is just a hot ball of gas with huge amount of debris floating around randomly in any direction

*Over a period of time a fundamental force called gravity pulls all this debris into a fiery ball of molten rock

*This ball slowly cools down and its layers start to get ordered by their own weight


Now considering all the matter on this tiny planet was once a chaotic jumble spread over many many million kilometers why would all of this rocky mess ever come together spontaneously via gravity. The earlier mess surely represents a highly chaotic state and a planet is mostly well arranged layers of solid and molten rock by their weight which by comparison seems highly ordered. So apparently a spontaneous decrease in entropy has occurred which is quite counter-intuitive to my mind. Could someone help me understand the relation between gravitational attraction, formation of planets and entropy
 A: The collapse of an interstellar gas cloud to eventually form a star, the formation of a planet, and the gravitational differentiation of a planet are all examples of exothermic (heat-producing) processes. As is the case with other exothermic processes, these processes increase entropy.
The cooling of a newly-formed planet has the appearance of an endothermic process. The decrease in entropy as a newly-formed planet cools is more than balanced by an increase in the entropy of the rest of the universe. That cooling is accomplished by radiating energy into space. That radiated energy represents a key concept in a newer understanding of entropy: In many cases, it's better to look at entropy as energy dispersal rather than some fuzzy concept of order versus disorder. The cooling of a newly formed planet is a perfect example of that.
A: What you have to look at is not only the order of the local product, but the energy and entropy changes of the entire system, i.e. the universe.
Before about 4.5 billion years ago the material that now forms the Earth was part of a sparse, cool accretion disk. As it collapsed into planet Earth, it heated up: kinetic and potential energy in the dust was converted into electromagnetic radiation which is flying off into space in every direction currently. That's part of the system we must consider when calculating the entropy changes. 
So you started with a small toroid of dust, which is only slightly ordered, which collapsed into an even smaller planet that is highly ordered, and also a sphere of photons which is completely unordered and covers a sizable portion of the volume of the visible universe. You can't stop at considering only the Earth or the solar system because that's not the entire thermodynamic system. The entropy of the heat loss into space must also be considered. 
A: The best explanation for this phenomenon (that is simple to understand even if you are not a cosmologist) that I could find was by MinutePhysics in this video: https://www.youtube.com/watch?v=MTFY0H4EZx4
