For me 2 sounds overengineered. Would go for 1 wit...
# codereview
e
For me 2 sounds overengineered. Would go for 1 with also scope function Like
Copy code
suspend fun createFoo(foo: Foo) {
    // Create record in DB and then perform additional tasks within scoped functions
    dbService.saveFoo(foo)
        .also {
            // Cache invalidation
            cacheService.invalidateCacheForFoo(foo.id)
        }
        .also {
            // Update search engine
            searchEngineService.addFooToSearch(foo)
        }
}
d
I'm not in a use-case/service (it's code others made - so I can't really start changing the whole architecture), I'm in the repository itself where the db request is being made... that's why I thought of the decorator pattern to separate responsibilites... but you're right, it would have been nice to put all this into a use case or service class... right now I'm trying to clean up what I can without breaking too much.
e
I thought your option 1 was a better choice of the 2 you mentioned , but I would add scope function .also.