The samurai had different functions in Japan, but their most famous role is as a warrior. But what set them apart from other warriors around the world was that they were educated, politically active elite class. Between 17th and 19th century, they became the ruling military class as well as Japan's largest social class and many od them were women.
The samurai were commanded by the emperor and the shogun. Japan was made up of smaller units, the shogunate, which was governed by a shogun, a military leader, and a top shogunate politician.
Although their role in Japan has changed over the centuries, the four items that define the term samurai have remained constant: 1. The samurai is a well-trained and skilled fighter; 2. The samurai serves his Daimyoi, with absolute loyalty, even to death; 3. The samurai is a member of the elite class, considered superior to ordinary people; 4. Samurai's life is ruled by Bushido, a strict code of conduct and a philosophy of life led by sense of honor.
Women in Japan had strong political power and they were also unrelenting warriors, known as Onna-bugeisha.
After 1867 when the Emperor established a professional army, the samurai started disappearing. Many samurai voluntarily joined the army and became officers supporting Meiji government defeating a series of Samurai rebellions.
After revolution in 19th century, samurai stopped fighting and become public officals adopting themselves in job needing their skills during the Japan expansion.
When the emperor government brought the law forbidding usage of swords, number of samurai grouped and rebelled against the emperor as their skills and code were dishonoured, however, they were defeated by much stronger army and disapeared completely.
The role of a samurai was to be loyal to their masters. They also had earned both military and political power over much of Japan before imperialism.