In dairy farming, social behavior plays a critical role in ensuring welfare and productivity of cows. Understanding social associations in dairy commercial farms could help farmers in creating herd management practices able to consider individual animal needs, in particular in stressful conditions as during regrouping. Here, we investigated the social behavior of 150 dairy cows during milking events in a free traffic barn at an Automatic Milking System (AMS) and we compared their social structure between their first lactation (when they were housed in the primiparous area) and their subsequent lactations in the multiparous area. Data on individual milking traffic and daily milk yield were collected for a period of 5 years and 5 months. To identify and analyze consistent social associations among cows, we utilized the time interval between milking events, which is defined as the time difference between the entry time of one cow and the entry time of the next in the milking robot. Our findings revealed significant social differentiations in both areas, indicating the presence of non-random social structures within the herd. During milking, younger cows exhibited a tendency to form stronger social associations with particular individuals based on genetic relatedness. The correlation observed between genetic relatedness and social behavior in young cows indicates that grouping genetically related individuals could provide advantages. On the other hand, as cows age, they tend to exhibit a higher degree of social connectivity with their herd mates. This suggests that older cows have a wider range of social associations which is not driven by genetic relatedness. We examined the potential influence of social associations on cow productivity, and we found no significant correlation between social behavior and milk yield for primiparous and multiparous cows. At a temporal level, we compared their ego-networks, when they were hosted in the primiparous area and when they were hosted in the multiparous area, and we found a significant level of social stability. Although the factors that influence social behavior in cows may differ with age, our findings indicate the tendency to maintain consistent social relationships over time. Maintaining stable relationships is crucial for enhancing the welfare of cows in social contexts, and this knowledge can promote the development of management practices aimed at supporting their social well-being. Our study highlights the importance of understanding social behavior and dynamics in dairy cows and offers valuable insights that can guide the development of effective herd management practices in the dairy farming industry.