Two of the earliest known civilizations to use a seven day week were the Babylonians and the Jews. The Babylonians marked time with lunar months and it is thought by many scholars that this is why they chose a seven day week (though direct evidence of this being why they did this is scant). That being said, each lunar month was made up of several different cycles—on the first day, the first visible crescent appeared; on approximately the seventh, the waxing half-moon could be seen; on approximately the fourteenth, the full moon; on approximately the twenty-first, the waning half-moon; and on approximately the twenty-eighth, the last visible crescent.
You’ll notice I used the word “approximate” a lot in there. This is because the moon phases don’t line up perfectly with this schedule. As such, as far back as the 6th century BC (which incidentally is also around the time the Jews were captives in Babylon), the Babylonians would sometimes have three seven day weeks, followed by an 8-9 day week, presumably to re-synchronize the start and end of the weeks to match the phases of the moon.
In their normal seven day week, the Babylonians held the seventh day of each week as holy, much like the Jews did and still do. However, the Babylonians also held the day to be unlucky. Thus, similar to the Jews (but for a different reason- the unluckiness of the day), the seventh day had restrictions on certain activities to avoid dire consequences from the inherit unluckiness of the day. The final “seventh day” of the month for the Babylonians was a day of rest and worship.
By deistic decree, the Jews also followed a seven day cycle with the seventh day- the Sabbath- to be a day of rest and worship. In fact, the word “Sabbath” comes from the Hebrew “shabbath”, meaning “day of rest”, which in turn comes from the Hebrew “shabath”, meaning “he rested”- thus resting in homage to God resting on the seventh “day” after creating the universe. (Note: some biblical scholars believe the “day” here, in terms of six “days” to create the universe, one to rest, is more accurately translated as “period” or “interval” rather than a literal Earth day. This is perhaps not unlike the “40 days and 40 nights” Jewish saying being a non-literal ancient Jewish expression simply meaning “a really long time”.)
Unlike the Babylonians, where it appears they were attempting to follow the lunar cycles with their seven day week, it isn’t known why the Jews picked seven days, outside of Christians and Jews of course believing that it was by the decree of God.
Whatever the case, the Ancient Romans, during the Republic, did not use a seven day week, but rather went with eight days. One “eighth day” of every week was set aside as a shopping day where people would buy and sell things, particularly buying food supplies for the following week.
Rather than labeling the days of the week with actual names, at this time the Romans labeled them with letters, A-H. You might think from this that the “H” was always the shopping day, but this isn’t correct. You see, the calendar year did not divide evenly by eight. Thus, the day of the week that was the day to go shopping changed every year, but they still often referred to days based on its proximity to the shopping day.
For reasons not entirely clear, within a century after the introduction of the Julian Calendar was introduced in 46 BC, the eight day week started to diminish in popularity in favor of the seven day week. The full switch was not sudden, happening over centuries, and for a time, as the seven day week grew in popularity, both the seven and eight day weeks were used in Rome simultaneously. Finally, after the popularity of the eight day week diminished to almost nothing, Constantine, the first Christian Roman Emperor, made the seven day week official in AD 321. Due to the influence of both Rome and Christianity, this has stuck in most regions of the world ever since.