Search code examples
design-patternsarchitecturesoftware-designdesign-principles

DAO as Service vs DAO as Library


I have 3 different services which needs to access same database. Each of these service will serve different purpose and different queries. I can generalize them in following way

  1. Service 1 -> Customer Inquires
  2. Service 2 -> Order Processor (e.g.workflow for placed orders)
  3. Service 3 -> Reporting

I have written a DAO to expose data. I am evaluating two system designs for scalability and maintenance.

Option 1: Write one more service to expose DAO functionality as Data Service.

Pros:

  1. Load on database will be controlled and easy to scale-in/out as needed
  2. Easy to maintain for future updates
  3. Access control for various actions
  4. clients doesn't have full access on underlying database

Cons:

  1. Single point of failure
  2. management of extra service
  3. Need to enforce backward compatibility rules
  4. In case of DataService downtime every service is affected (factors other than database downtime)

And

Option 2: Create a storage library out of DAO and use these library in above mentioned three services.

Pros:

  1. distributed, impact radius is very small

Cons:

  1. Every service get full access on database
  2. Needs to update all three services for new features
  • Which option is good and why?
  • Any other ideas/architecture designs to consider?
  • What are the things I need to consider when choosing architecture?

Solution

  • Thank you Rob and Maksym for your inputs.

    I separated queries based on bounded context and created library and service for different context.

    Service

    Inquiry and Order Service access data using data service. This helped me control noisy neighbor and resource allocation.

    Library

    I replicated data from main database to reporting database and built a library for Reporting service to access reporting database.