![]() Our product was initially written using ORM and we ended up rewriting it using layered architecture, DDD and CQRS, it's much easier to reason about now (because all DB access is encapsulated in one place and doesn't spill over the rest of the application), and we're in the process of moving away from ORM in our CRM as well. it's harder to debug because there's a lot of magic no table locking, support for custom sharding etc.) so you end up writing cutom tools tailored for your use cases anyway with a large amount of data (millions/billions of rows), built-in ORM stuff stops working when you care about zero-downtime migrations (i.e. ORMs often encourage coupling business logic with DB access logic so it becomes harder to write tests and refactor code escape hatches in the form of raw SQL increase cognitive load (2 ways to do the same thing, having to always remember how ORM matches to SQL and back when writing business logic) and may introduce inconsistency/bugs when the ORM caches object state in memory while raw SQL doesn't and you accidentally mix the two in one request (we've had a few such bugs) N+1 query problem leading to subpar performance (down to unusable) I have quite the opposite experience: you start with an ORM because your app is a simple CRUD, later when the app becomes more complex and the team/userbase grow, you start having problems: The issue with ORMs really come down to restrictions on escape hatches, easy dropping down to SQL but with mapping back to your higher level abstractions. But the majority of the time it's better to start with an off the shelf ORM than not. Obviously the world isn't that simple, and there are legitimate reasons not to use one. you write a database migration tool, reuse a bunch of your application table abstractions as the definitive source of truth for what your tables look like. Then one day someone runs the wrong migration and drops the main db. Hand writing database migrations is simple to start with, but as your team grows, and you have more deployment environments, and more branches, it becomes a massive headache. So you generalise it to be usable on other tables. You write a query builder for one area of you application, but soon find yourself longing to use it elsewhere. You start writing more complex queries based on user input, it starts to get a little complex with all the string concatenation. You find yourself duplicating code for simple select/update/insert/delete quires so you build another layer of abstraction so you have only one generic implementation of these that your table row abstractions use. It handles deserialising/serialising from the database types to you languages types, plus a few of your custom types. First job is to write a few abstractions that represent a row in each the tables in your db. You design your database schema, start building your application, inserting, updating, querying it. You start of thinking, my problem is simple/unique so I don't need an ORM
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |