Selecting best database

Sort:
josephtheuniversalis

My three software developer colleagues and I are working on developing a turn-based game with logic similar to chess. We have some questions regarding the best way to store data, moves, and sessions. We believe that relational databases such as Oracle and MySQL might not be the best fit for our game's requirements.

We are considering using MongoDB or Redis, but we are not fully aware of the advantages each might offer in this context. Could anyone provide advice on which database would be most suitable for our needs and in what scenarios each option excels?

carbo2000

is not better to ask in stackoverflow?

rubik28917

I agree about asking in a forum with a *much* wider readership. The issue isn't really about chess.

Also, what are your requirements?

  • How much data will be stored?
  • How fast will it need to be accessed?
  • What is the ratio of reads to writed?
  • How often will data be deleted?

Things like that. Here's one few people think about: *gobs* of people know SQL, probably more than other database language. There are more highly tested and full-featured libraries for working with SQL than other types of databases. Does that matter to you?

Note that I'm not expecting answers. The process of defining your specific requirements will help you make a better decision for this particular project. Sounds like fun, good luck!

YankeeBastid

[Removed HTML tags; DS]

If you have it, I use ChatGPT4o for all my db questions. I have found it to be helpful in so many ways, that it would be impossible for me to describe them. I can hand it a 1300-row script and have it point out the weak spots in my loops and other little items that make the life of a coder difficult I am sure it will have something to say about your requirements. Here is what it said about your question.

When choosing between relational databases like Oracle and MySQL and NoSQL databases like MongoDB and Redis, it's crucial to consider the specific requirements and characteristics of your game. Here's a comparison of MongoDB and Redis, highlighting their advantages and best-use scenarios:

MongoDB

Advantages:

Document-Oriented Storage: MongoDB stores data in flexible, JSON-like documents, making it suitable for applications with unstructured or semi-structured data.
Scalability: MongoDB is designed to scale out horizontally by sharding data across multiple servers.
Schema Flexibility: The schema-less nature allows for easy modifications without requiring downtime or complex migrations.
Rich Query Language: Supports complex queries, indexing, and aggregation, which can be useful for querying player stats, game histories, etc.
Geospatial Queries: MongoDB has robust support for geospatial queries, beneficial for location-based games.

Best Use Cases:

Games with complex, nested data structures (e.g., player profiles, inventories).
Applications needing frequent schema updates and flexibility.
Storing game events, logs, and analytics.
Redis

Advantages:

In-Memory Storage: Redis stores data in memory, providing extremely fast read and write operations.
Data Structures: Supports various data structures like strings, lists, sets, sorted sets, hashes, bitmaps, and hyperloglogs, which can be useful for leaderboard rankings, player sessions, and real-time analytics.
Pub/Sub Messaging: Built-in publish/subscribe messaging system useful for real-time updates and notifications in games.
Persistence Options: While primarily in-memory, Redis can persist data to disk, offering durability options.
Atomic Operations: Supports atomic operations on these data structures, ensuring consistency and reliability.

Best Use Cases:

Real-time leaderboards and scoring systems.
Caching frequently accessed data to reduce latency.
Managing user sessions and fast access to game state data.
Real-time analytics and event streaming.
Choosing the Right Database

MongoDB is ideal if:

You need a flexible schema to handle evolving data models.
Your game involves complex querying, analytics, and reporting.
You require horizontal scalability to handle large volumes of data.
You need to store and query rich, hierarchical data structures.

Redis is ideal if:

Performance and low-latency access to data are critical (e.g., real-time leaderboards, session management).
You need to handle real-time updates and notifications efficiently.
You want to use advanced data structures for specific use cases (e.g., sets for managing player achievements).
In-memory data storage fits your application’s requirements for speed and can manage data persistence as needed.
Conclusion

For a game that requires real-time performance and complex data structures for features like leaderboards, player sessions, and real-time analytics, Redis would be a strong candidate due to its speed and versatility.

For a game with complex, flexible data models, rich queries, and the need for scalability, MongoDB would be more suitable.

In some cases, a hybrid approach might be beneficial, where you use Redis for performance-critical operations and caching, and MongoDB for more complex data storage and querying needs.

muzzleplayer

Not sure what's ur idea is, but I had developed one file based database for storing chess games and positions. I am using the same on scriptches.com. I have explained my approach here https://scriptchess.com/articles/how-to-create-database-for-chess-from-scratch

I hope it'll help you

GM_Salzi

If i would program a chess website from scratch i would use a sql database with two tables:

user with all the necessary user information + a session id to track the game they are currently playing.

game with a foreign key to both players of the game and the pgn of that game.

This approach would cover all basic needs you could have.

If you do not want to use sql i would strongly recommend mongodb, because it is a lot more free for the schema.

Do not use redis, they are currently building very big shit with the open source licensing. If key-value i would recommend keydb. Its open source and basically the same as redis.

If I had to choose between mongodb and keydb i would choose mongodb you have a lot more possibilities with your schema and you are not limited to key-value.

If you have any more questions feel free to dm me, i have done several projects with diffrent databases already.

scooter_de

Use an SQL database and be done with it. I'd go with SQLite or Postgres depending on your use case.