> I was surprised how easy it is to express pretty complicated game logic in SQL. The game logic is just ~5900 lines of SQL.<p>I still think HN is taking major naps on the capabilities of contemporary SQL.<p>There are businesses so complicated that maintaining procedural code over the domain is largely infeasible. Implementing business rules in SQL can decompose the problem in ways that allow for a lot more people to interact with it at the same time.<p>When I was working in semiconductor manufacturing, we relied very heavily on stored procedures and SQL to operate the factory. Very little operational decision logic existed in code. We had hundreds of users who were inspecting and proposing changes to the same set of procedures. Testing this stuff was trivial because we replicated the prod DB every morning and experimented against live data directly. There was no gap between the information of the business and its logic. Most shops are not ran this way. They treat the database like some CRUD retrieval engine instead of the nexus of both the data and logic.<p>When people advocate for spending big piles of money with Microsoft, Oracle and IBM, they are generally going for something like the above. They want literally one system the business operates inside of. Spreading a solution across 10+ vendors and tools when you could do with one is borderline negligence depending on your role in the organization.
Its always a very interesting architectural question when deciding at what level(s) the business logic should live. There absolutely are valid reasons for some to go in SQL, though I tend to avoid putting the most complex logic there when its really tricky.<p>When it really gets hairy, or when the business logic keeps changing under my feet, I'll try to find constraints I can put in the db as a final backstop while leaving most of the logic somewhere in the application stack.<p>I can count on one hand the number of people I've worked with that really know SQL well enough to pick up complex business logic at that layer and work with it easily. I've been mainly in small companies for the last decade, I'm sure at larger orgs there are more data engineers running around that could own it.
There are very few things I would want to do less than complicated logic in SQL. At least these days we get the alternative of SpacetimeDB functions <a href="https://spacetimedb.com/docs/functions" rel="nofollow">https://spacetimedb.com/docs/functions</a> But having everything in stringly typed environment with minimal stdlib in things like mssql? Yeah, there's a reason why it's not a popular pattern.
I hated debugging and fixing stored procedures for legacy 2000s apps in de 2010s. The SP code wasn't treated like regular code, it wasn't source controlled. Mostly bad memories from having business logic inside the DB instead of having it all inside the code.
> we replicated the prod DB every morning<p>You may be storing logic in your database, but most businesses store data in their databases, and the amount of data they store (mostly because they can't tell what's important and what's not) makes copy-pasting their database every morning pretty unrealistic.
True. The kind of guarantees you can get when staying within the database can often solve whole categories of problems. But, DX of having non-trivial logic inside Postgres is not great either: I feel that I'm making a significant trade-off. I've also seen interesting languages that compile to SQL, would consider those in some cases.
Less lines of code than vanilla C while abusing query planning as a state machine is peak engineering malpractice. I love it.
Yes, this is fantastic! I'm trying it right now. I look forward to the day when LLM inferencing can be done in a sql query and take less than the age of the earth to do something. This works way better than I would have expected, since, well, it's sql all the way down.<p>I noticed the cedardb.com blogpost on the project is slashdotted at the moment, but the game itself plays just fine.
Off topic, but say you have a program that needs to calculate something but takes a long long time, how to counter hardware failure without needing to calculate everything from the start?
I think you could do that already. Just store your weights in a table...
[flagged]
MY PEOPLE!<p><a href="https://github.com/seanwevans/pg_shell" rel="nofollow">https://github.com/seanwevans/pg_shell</a><p><a href="https://github.com/seanwevans/pg_gpt2" rel="nofollow">https://github.com/seanwevans/pg_gpt2</a><p><a href="https://github.com/seanwevans/pg_os" rel="nofollow">https://github.com/seanwevans/pg_os</a><p><a href="https://github.com/seanwevans/pg_git" rel="nofollow">https://github.com/seanwevans/pg_git</a>
The game state being a SQL table just kinda triggered a memory of a year of optimization for me. One thing I'm still unsure of being a good decision or a bad one, when I wrote my casino in 2010, was having every remote call update game states on SQL tables that were used as the source of truth. With multiple players you can imagine that there would sometimes be issues. Some of the deadlock problems early on were horrific; scaling was a nightmare. But everything was atomic. No risk of lost data beyond one turn not reaching the server or deadlocking, nothing like a huge nodejs process choking on everyone's calls at the same time, or losing its memory. You always had <i>state</i>.<p>Looking back it seems like not a terrible design pattern for multiplayer turn-based games, if you can work out the kinks. Atomicity guarantees at least that there <i>is</i> a consistent state that won't get lost. Doing that read/write loop for an action game? Pure folly, but it's pretty funny to me.
There is a whole chapter in Designing Data Intensive Applications dedicated specifically to handling atomic transaction concurrency issues while avoiding the performance trade-off you're describing here, you will definitely find it interesting.<p><a href="https://www.oreilly.com/library/view/designing-data-intensive-applications/9781098119058/ch08.html" rel="nofollow">https://www.oreilly.com/library/view/designing-data-intensiv...</a>
If you squint and ignore the brain damage, SQL is kind of... functional.<p>Almost. In a way.
if is TC it can run Doom.
This should be illegal :)))) Wow!
Meanwhile I'm too inept to get WordPress to load dynamic content faster than molasses.
I want to point out that they set up an EU and US multiplayer server! Nice touch.
This is the kind of content I want to see on HN! Pure art.
Nice piece of advertisement.
Kind of hard to stand out in the world of SQL dbs. That definitely raised eyebrows.
> The game logic is just ~5900 lines of SQL. While this sounds a lot, it’s definitely less than the original C source code which does the same in about 9000 lines!<p>Nice
It's fascinating that it can be applied this way.
Thats ridiculous I love it. The visual in the bottom right it a great illustration.
[flagged]
[flagged]
[dead]
(This has been posted numerous times but none of them made the front page. I've made a new copy of the earliest one that got comments.)
[flagged]
"Query III Arena", please. /s