Hi @kossjunk and a warm thanks to @Dent for the @ mention.
There are many paths to answer your question @kossjunk and all roads lead back to your experience with programming and IT in general and also the context of the application you are developing.
Based solely on the tone of your question @kossjunk, it is probably best to approach this in a top down manner, so that’s what I will do below.
Managing chats by multiple users are little different than managing topics and posts by multiple users in this Discourse community we are chatting in now, or how the ChatGPT all manages users, topics and chats, or how a WordPress blog manages multiple users, topics (articles) and replies. I think you can see where I am going with this analogy, or ‘super high-level architecture’.
You need a data model for users, topics and chat entries (posts). The data model for users can be as simple as the numeric id (user_id) and password (stored cryptographic password hash), or it can be a model which includes name, phone number, email address, twitter user name, location, and user preferences.
This means it is important for you to visualize what your data model is for your users. For example, let’s say your application permits individual users to fine-tune GPT-3 models; then you will need to model this for the users DB table. In that case, you may even require a DB table for models where you can associate fine-tuned models with user ids.
In other words, the core of developing an application is to consider the data model based on how you envision the application to work. Normally, developers look at this using a high level view. such as “model, view, controller” (or something similar based on experience and style), but in general we separate the data model from the visual part of the app the user sees and the logic which glues it all together.
So, while you are considering the data model for your users, you can simply and easily (and cost and time effectively) look at the open source code for the countless forums, blogs and other data driven applications freely available which all have users, topics and posts. There are countless free and open source applications which have this same basic structure. Managing users, chat topics and chat replies are no different. I recently wrote two Discourse plugins which store OpenAI replies (both text and images) as posts in a forum, so I used the core DB tables of the forum software in these relatively simple Discourse plugins.
Normally, you will see a table for users, topics and posts. Generating these DB tables does not require much thought about things like “primary keys” as suggested by someone else at this point. For example, if you develop using Ruby on Rails (just an example), the basic primary keys are generated for you when you generate a model and later on, you may start creating indexes (to speed up the DB if you application grows large), but that is something far down the road if you have not created any models or built any application logic. In other words, there are many tools available to help you generate models depending on the programming language and development environment you are working in, which can range from your personal favorites to what your organization requires you to use.
So, in summary. When you @kossjunk ask “@dent how can one save chat for very many users?”, this implies you are not (yet) a developer and do not (yet) have experience with application development in general. Assuming this is the case, you have to consider your business model and if you want to learn how to develop an application (which takes considerable personal time and effort) or to get someone else to do it for you.
But, in a nutshell, you can look at the open source models for any forum (like this one) or blog which has multiple users, topics and posts and that will illustrate how to think about the data models you need for a basic multi-user application which has topics, like we see on the left sidebar of the ChatGPT application, and posts (chats), which we see very prominently in the ChatGPT app.
Hope this helps.