Method – GET /search
Input – user_id, query
Output – suggestion (string)
Method – POST /suggestion
Input – user_id, query, suggestion, decision (accept or reject)
For the search database we will use reverse index data structure, that supports full-text search.
Key – query
Value – possible suggestions for this query
We can use table-like data structure for the history of users decisions.
Columns:
The table may be partitioned by date, because we usually need the most recent users decisions
Search flow
Search database is built on Elasticsearch technology. It supports horizontal scaling.
We use ScyllaDB for users decisions database. The history data will be sharded with user_id as a key, because we always retireves data for a specific user. We also use partitioning using date of the decisions. So we can store last and most relevant decisions on the fast part of the database.
The users decisions cache will be horizontally scalable using Redis Cluster technology.
All the services are stateless, so they are well scalable horizontally.
All the databases are also highly scalable and available.
We may optimize the ranking algorithms, so users will like the suggestions more. We also can add some more caching in the search flow, if we will need to decrease latency.