The study of the dynamics of opinion formation and transmission in social networks has attracted lots of attention. Here, we propose a model that simulates communication in an online social network, in which randomly created posts represent external information. We consider users and friendship relations to be encoded as nodes and edges of a network. The dynamic of information diffusion is divided into two processes, referred to as post transmission and post distribution, representing the users’ behavior and the social network algorithm, respectively. Individuals also interact with the post content by slightly adjusting their own opinion and sometimes redefining friendships. Our results show that the dynamic converge to various scenarios, which go from consensus formation to polarization. Importantly, friendship rewiring helps promote echo chamber formation, which can also arise for particular networks with well-defined community structures. Altogether, our results indicate that the social network algorithm is crucial to mitigate or promote polarization.