I just read the Hystrix docs/wiki and still am missing something at a fundamental level: what is the intended level of granularity for a HystrixCommand
impl?
For instance, say I have a DAO object that handles CRUD operations for some DB entity, say, a Widget
:
class Widget {
Long id
Long typeId
Long version
String name
Boolean isAlive
}
interface WidgetDao {
Widget insertWidget(Long typeId, String name, Boolean isAlive)
List<Widget> getAllWidgets()
Widget getWidgetById(Long id)
void updateWidget(Widget widget)
void deleteWidget(Widget widget)
}
Now, if the database that this DAO connects to goes down, all the DAO methods will begin failing. But I suppose it is also possible for the DB to be tied up in some transaction or maintenance mode, where say, reads are permitted, but not writes. In that edge case, reads would succeed (the getX(...)
methods), but all others would fail with SqlException
s.
So I ask: what's the intended level of granularity that I should be using here? Either:
- One
HystrixCommand
impl for every DAO method, seeing that in some cases the commands could be running successfully, and in others, they could fail; or - One
HystrixCommand
somehow baked into the DAO class, spanning all DAO methods (ergo if one command fails, the DAO as a whole "goes down".)?
I think the former represents more flexible engineering, but introduces a lot more code to me as a consumer of the library. Thoughts? Ideas?