Sites that let us get in touch with other users to speak our minds, exchange opinions or share interesting things have been around for a very long time. As internet users we have been through many forms of this kind of communication: chats, newsgroups, online forums... Then at some point technology allowed ever more advanced sites, where more people could join the discussion. Today social networks are neither a novelty nor something exciting. Mainly because they have soaked into our lives so deeply that for some they are an everyday routine and even an "obligation" they are not aware of, and for others something they can fight against.

Such widespread use of "social media" brings difficulties for developers as well. These are now such huge undertakings that it is not easy to break through with your own, potentially innovative idea for an online place for a community. As a result, even though quite a lot of new networks appear, most of them cannot stay on the market for long, even if they introduce something new. Snapchat was such a novelty at one time, and its ideas were absorbed by other services. TikTok is on top right now, and it has indeed stayed afloat for quite a while thanks to an interesting (or valuable, that is another matter) idea of its own. Not long ago a test version of Clubhouse appeared, which bets on voice communication and skips text altogether.

Still, there are more ideas for social networks than are actually built. This is not exactly news, but it is worth thinking about why. After all, such a site seems fairly simple to build, and an uncomplicated idea could even be a good exercise for a programmer, with something interesting coming out of it along the way. In the same way, a simple MMORPG could be a warm-up for a young video game creator, yet everyone strangely recommends, say, platformers. So where is the catch, and can building a social network actually be easy?

You can probably guess the answer, and the launch of the Albicla.com site in early 2021 largely gave it to us. The whole Polish internet community ended up analyzing that case, and I would especially like to recommend the articles by Tomasz Zieliński on his blog InformatykZakładowy.pl (the first and second text). Let us analyze such a project calmly, because I think it is a good exercise (even a mental one) for developing your skills in architecture design.

The idea and the basic functionality

Everyone will probably agree that every application (and a social network in particular) needs a good idea. You need to know who the site is for, what kind of content users will be able to post, what can be done with those posts, and so on. Let us take the basic, almost textbook concept and use the descriptive form to present it:

As a user, I can browse posts published by other users on their profiles. To publish content myself, I have to register, confirm my account and log in. As an authenticated user, I have a special page (called the "wall") where the system shows me posts published by the profiles I have followed. I can like any post, share it on my profile and leave a comment.

As you can see, in theory the functionality looks fairly simple. Here we have:

  • displaying a profile,
  • displaying posts (filtered by profile or by follows),
  • registration,
  • logging in,
  • publishing a post,
  • displaying the wall,
  • liking a post,
  • sharing a post,
  • commenting on a post.

Of course, this list is not closed, since we would probably also want users to be able to undo their actions, recover a forgotten password, log out and do other things. Even so, it all still sounds like fairly simple functionality, technically within reach of someone who is only on the way to becoming a programmer, and not over a year but over a few months or (for a simplified version) weeks. Frankly, it looks like a good project for passing a semester course or a topic for an engineering thesis.

But this article would make no sense if everything turned out to be that simple, right? First, every widely used application requires that its features be well tested and work correctly, so the delivery time would have to include verification and fixes. And second, the list above is only the tip of an iceberg whose existence you have to keep in mind, because it comes in a package with the decision to start building and promoting a social network.

Now let us go through what that iceberg consists of.

Performance and throughput

Functionality is the most important thing, but it is not everything. Would we use Facebook, Twitter or Instagram if they worked correctly but very slowly? Notice that displaying posts on the wall means running a database query with the right criteria. Those criteria can be quite complicated, depending on how we store data such as the profiles a user follows. What is more, there may be many such queries every second (for each user separately), and on top of that the system should refresh the information on its own from time to time, showing whether the recipient has a new message to display. And as if that were not enough, all of this runs on a database that is under load the whole time.

Of course, for a simple social network for a dozen or a few dozen people these limits do not matter much, but a social network is not built for a limited number of people. It is built for thousands, even millions. At that point you have to take care of the performance of various operations, especially fetching data (how fast information is displayed), as well as throughput (the ability to serve a large number of people at the same time). This is closely related to scaling, which we wrote about in a post some time ago. If our social network is slow, it will put users off, and they will look for an alternative.

Any work in this area strongly affects the internal construction of the application and the way data is stored. This means many architectural changes or (better) designing the system from the start in a specific, not necessarily trivial way. In addition, the data will probably come with many statistics and accompanying information, so writing and reading it will have to be cached. That in turn means thinking through the synchronization of subsystems and sometimes a compromise between speed and delivering consistent messages on time. For example, on Twitter there are situations where you can see the same tweet side by side on two timelines with different statistics, or where notifications briefly disagree with the number of likes. That is exactly the effect of such compromises.

So building a correctly working social network is not necessarily a complicated or labor-intensive programming task. But adding the optimization needed to serve many people at once (who are, after all, the heart of such a site) takes the right knowledge and architectural experiments, which greatly affect later optimization.

Security

The challenges facing those who work on applications today largely come down to securing them on many levels. Different areas are considered for software aimed at a narrow group of users (for example specific companies) than for systems built for the mass market. This is especially true because social networks often involve exchanging private messages, as well as attempts to peek into something in the system that a given person should not have access to. And it does not matter that users are sometimes to blame themselves for publishing sensitive information online. The job of developers and administrators is to make the system protect against unauthorized access and attempts to "blow up" the site as effectively as possible.

It has also long been known that security affects how convenient it is to build an application and how well it performs. On one hand, you have to maintain the right level of user trust. On the other, the mechanisms cannot drastically affect how comfortable the application is to use (unless that is the strength of the service and we assume users are aware of it). So this is another architectural challenge that affects the implementation process.

One thing to watch is the content published by users. On one hand, we may be dealing with "smart alecks" who try to make the system malfunction with specially crafted posts. This also includes spam, for example, which you have to guard against (and which again affects performance). On the other hand, we will certainly see behavior that breaks the terms of service. The mere existence of such content will be discussed in another paragraph, but inevitably not everything will be blocked in time, which can affect not so much security itself as how the service is perceived by users who expect that security. Especially since, as I wrote earlier, social networks still have things to fix here.

Aesthetics and accessibility

Social networks have to be pretty and clean. They do not always catch the eye with their layout alone, but the content shown on them should be clear and the available options properly marked, considering that users will be very diverse. And even though there are not always many elements on the screen, they have to be organized logically, showing visitors that they will feel at home here. The creators of such systems want exactly that: users who come back to their sites willingly.

What is more, social networks are specific in that users often visit them out of boredom, to scroll through the feed and see what their friends or the profiles they follow have posted. This means the content is displayed in all kinds of conditions (for example on public transport), on different devices, and each time it has to be clearly visible and the service comfortable to use. This is a challenge for those who work on the interface and the so-called user experience, and again it calls for a well-designed architecture, this time of the frontend.

As if that were not enough, there is also the decision about a possible (and often mandatory) mobile app and the features it offers. In this case, though, the situation sometimes gets simpler, because some social networks work only on smartphones or offer the lion's share of their functionality there.

Data volume

This topic is related to the section on performance and throughput, but it needs to be stated clearly: in a short time the creators of such a site will be dealing with a huge amount of data. This means taking care of a proper database structure, column indexing and query design so that queries do not take ages to run. But that is not all.

A lot of data also means a lot of notifications, in various forms depending on the profile of the site: counters popping up in the interface, push notifications, emails, SMS and so on. And all of that has to be sent in a way that does not clog the communication channels. Not everyone wants to receive every piece of information either, so you need a subsystem where the user decides what they want to be notified about.

Sometimes we also want to filter information across the whole site by hashtags or simply keywords. That creates a need to search the posted content, and in a way that does not take hours. So you may have to choose a specific database management system, or several engines at once, from the very beginning, which has its consequences and certainly does not make building the site any easier.

Along with this comes the need to collect statistics (the number of likes, for instance), where once again we face a compromise between counting on the fly (hardly feasible on large sites) and storing previously saved values that may be out of date by the time they are displayed. What is more, a suitable business model may require collecting a lot of data about users (let us set GDPR and privacy policy issues aside for a moment) that is not visible at first glance. This information has to be stored somewhere and then used, so you need to warehouse a truly enormous amount of it.

Administration

We keep looking at the technical details, but remember that a social network is not only a technical matter. Of course, every site needs terms of service and support, but we probably do not appreciate the team of consultants and analysts behind every social network, who let it operate and make money. Remember that today such services are not only a place for friends to exchange information, but also marketing platforms for companies, some of which build their whole business on them (whether that is wise is another matter).

So you need people who will prepare and keep updating the terms of service (including the sections on user data, which is very important now), moderate content, handle support, analyze the market and the audience... That means a really large team, which may be small at first but, as the site grows and users arrive, will have its hands full. Especially the moderators, who have to deal not only with a large amount of data but also with indecent content that they must look at before judging it, and we have already mentioned that users can be spiteful.

Let us go back to the technical people for a moment. To serve a very large number of users you need an advanced architecture and many servers, which means significantly expanding the team responsible for administering the infrastructure. Programmers have plenty to do as well. Creating the site itself may not seem all that complicated (which is, of course, an illusion), but afterwards every change has to be introduced carefully. Social networks usually also have many subsystems for things that only business partners or data administrators see, for example. It is a huge machine that, with great popularity, requires great human resources.

Business model

When we build an application mostly for learning and killing time, we do not think about how it could make money, but in any business venture this question is fundamental, and sites have already collapsed for lack of decisive action here. The business model matters because it has to take into account both the popularity of the site (so closing it to paying users only can be the nail in the coffin) and the willingness of users to pay. It is no accident that many services rely on ads, since this gives many millions of users the illusory feeling that it is free, while everyone leaves a trace in the form of data that is processed later. This also shows that the decision on how to earn money from the site must come with specific technical decisions, a design for storing and handling information, and so on. There would be many more active social networks if only there were more creative ideas for using them to make money. And giants like Google with its Google+ have already failed here.

Summary

Building your own social network can be an interesting experience and exercise for programmers, because it lets you sharpen your skills on a fascinating project. We have to remember, though, that a correctly working social network is one thing, and a GOOD social network is another. The latter usually requires a much more extensive architecture, which in turn lengthens the delivery process or forces compromises in several areas. And it can still be a good exercise and experience. The only question is whether it pays off to take it on when the team lacks the right resources and an idea for turning them into profit.

Best regards and thank you, Jakub Rojek.