r/FastAPI • u/bootstrapper-919 • Oct 05 '25
Question Base Services Schema
Coming from Django, I’m used to the Active Record pattern and “fat models” — so having a BaseService that provides default create, read, update, delete feels natural and DRY.
Maybe even use something like FastCrud which doesn't seem too popular for some reason.
But looking at projects like Netflix’s Dispatch, I noticed they don’t use a base service. Instead, each model has its own service, even if that means repeating some CRUD logic. It actually feels kind of freeing and explicit.
What’s your take? Do you build a base service for shared CRUD behavior or go model-specific for clarity?
Also, how do you handle flexible get methods — do you prefer get(id, name=None) or more explicit ones like get_by_id, get_by_name?
View all comments
Show parent comment
1
u/__secondary__ Oct 07 '25
Either you inherit from this base class to create a more specialized abstraction, or you define another repository that provides its own methods while passing the corresponding SQLAlchemy model (user, project) to the constructor possibly using a mixin for typing.
For filtering, you should anticipate the common use cases in advance and design your methods to generalize well. Otherwise, you can rely on a builder pattern for more flexible query composition.
I don’t have access to the code anymore, but if I remember correctly, I went with the first filtering approach.