Profile picture
Simon Willison @simonw
, 4 tweets, 1 min read Read on Twitter
This is one of the main benefits I see of a "service" abstraction - be it a networked microservice or just a class that encapsulates some core business logic. A lightweight layer for reading and writing the DB.
A big reason this is useful is that in any large system those updates are likely to be denormalized in some way - a write to the DB may also need to also invalidate a cache or refresh a separate search index. So all updates should share a codepath.
And for reads in a large system speed is crucial. It's much easier to avoid pathological query performance if reads are all made through some kind of getPostsByIDs method that knows how to efficiently batch queries and uses optimizations like Django's select_ and prefetch_related
For smaller projects (especially proofs of concept) I go entirely the other way: the smallest amount of tightly coupled code that can illustrate the desired result. Knowing when to architect for scale (both in traffic and the size of the maintenance team) is art, not science
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Simon Willison
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!