Widely considered to be the 18-20th century predecessors to the modern day Yakuza, we have the Bakuto and the Tekiya.
The former refers to a class of itinerant gamblers, while the latter to travelling peddlers.
Similarly to their peers of Tekiya, the Bakuto were considered to be social outcasts and pariahs. They spent much of their time travelling from town to town or settling down upon Japanese highways in order to gamble with locals. Games often held by the Bakuto included traditional games played with Hanafuda cards (literally: flower cards.) Which were typically organized into months and displayed images which could be combined together as a set. Several games can be played with these cards, including Go-Stop, Seotda, Doryjytgo-ttang, Koi-Koi and Mushi.
These early gambling rings were sometimes even hired by local governments in order to win back the wages of local labourer's for a percentage. They had many traditions as well that we now see as having evolved into the structure and cultures of modern day Yakuza. Such as elaborate full body tattooing - which was sometimes displayed by Bakuto members during games. As well as traditions of apology through self-mutilation, known as Yubitsumi.
It is said that the Bakuto are even responsible for coining the term 'Yakuza', which is said to come from the worst possible hand a player can have in a game of Oicho-Kabu. That hand being '8-9-3' which is pronounced 'Ya-ku-sa' in Japanese, and is synonymous with 'useless' as a result. A sentiment shared with many social outcasts of the era for how they imagined society viewed them.
Beyond the Bakuto, we have the Tekiya. If we are looking at how they are viewed publicly, their hosting of festivals, and if we wish to compare their nomadic lifestyles to something relatable, we might compare them to North American carnies.
But that is where the comparisons end.
Similarly to the Bakuto, the Tekiya would travel the countryside. Visiting villages or taking short stops along highways in order to setup stalls through which to peddle their wares. Typically hailing from lower castes, Tekiya held reputations that left them being remarked as disingenuous and who scammed people out of their money with low quality good.
They were a hearty people however, and lived by strict codes of ethics that we still see today. They were pioneers of the oyabun-kobun system the Yakuza have become famous for. A system that renders the Oyabun, or 'boss' a kind of father to his Kobun 'students' or 'children'. It fosters kinship and familial loyalty within the organization.
Given the nomadic nature of both of these styles of people, one can understand how fugitives, bandits in hiding or other criminals might have entered their ranks.
And so, as the Bakuto began to engage in crimes such as loansharking, the Tekiya began to undertake practicing protection rackets or becoming involved in turf wars with other bands of peddlers.
Through this we can see how they began to evolve to become the organized crime groups we see operating in Japan today. Of course there are still Tekiya bands operating in the modern world and there are surely Bakuto rings as well, but somewhere along the line these groups merged as one to form the Yakuza we now know and fear.