question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can the write database be different to the read database in terms of the data it holds i.e. fields/tables included in one that are not included in the other?

See original GitHub issue

Thanks again once again for developing this app. I am developing an application using the CQRS pattern. The read database is: MongoDB (NoSQL) and the write database is SQL Server.

Please see the code below:

public class Product
    {
        public Guid Id { get; set; }
        public string Code { get; set; }
        public string Description { get; set; }

        public void LookupDescriptionByCode(List<ProductDescriptionLookup> productCodes)
        {
            Description = productCodes.Find(x => x.Code == Code).Description;
        }
    }

    public class ProductDescriptionLookup
    {
        public Guid Id { get; set; }
        public string Code { get; set; }
        public string Description { get; set; }
    }

The database (lookup tables) looks like this:

create table ProductDescriptionLookup(Id uniqueidentifier, Code varchar(100), Description varchar(100)) insert into ProductDescriptionLookup (Id,Code,[Description]) values (newid(), ‘prod1’,‘Product1’)

Here is some test code for the write side:

[Fact]
        public void Test()
        {
            List<ProductDescriptionLookup> list = new List<ProductDescriptionLookup>();
            list.Add(new ProductDescriptionLookup { Id = Guid.NewGuid(), Code=  "prod1", Description="Product1" });
            Product p1 = new Product { Id = Guid.NewGuid(), Code = "prod1", Description = "" };
            p1.LookupDescriptionByCode(list);
        }

Here is the read model (which is mapped to a MongoDB database):

public class Product
{
	public Guid Id { get; set; }
        public string Description { get; set; }
}

Notice that the Product Code is not even persisted to the read side. Therefore there is no need for the lookup table on the read side (because it will never have to lookup the description by product code). Therefore I am planning to exclude the ProductDescriptionLookup table from the read side. This works perfectly from a technical point of view, however I am wandering if it is frowned upon from an architectural perepective as the read database is now different to the write database?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
w00519772commented, Feb 8, 2019

@mvelosop, yes the question was answered - thanks for the answers. I thought a question about the architecture used by eShopContainers would be on topic - apologies if I have gone off topic.

0reactions
mvelosopcommented, Feb 8, 2019

Hey, no problem @w00519772, this is all fun and it’s easy getting carried away 😉

Best.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CQRS pattern - Azure Architecture Center
CQRS stands for Command and Query Responsibility Segregation, a pattern that separates read and update operations for a data store.
Read more >
Database Design: A Point in Time Architecture - Simple Talk
Point in Time Architecture (PTA) is a database design that guarantees support ... In all likelihood, the data modeler, DBA, or SQL programmer...
Read more >
What is a Relational Database?
A relational database is a collection of information that organizes data points with defined relationships for easy access. In the relational database model ......
Read more >
Database vs Spreadsheet: Full Comparison
What sets these two data science terms apart: database vs spreadsheet? We compare their pros and cons, similarities and differences. Read ...
Read more >
What is a Relational Database (RDBMS)?
A relational database is a type of database that stores and provides access to data points that are related to one another. Relational...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found