{"id":12541,"date":"2022-10-01T02:23:00","date_gmt":"2022-09-30T20:53:00","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/"},"modified":"2022-10-01T02:23:00","modified_gmt":"2022-09-30T20:53:00","slug":"solved-what-is-a-combo-repository-and-a-service-bus","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/","title":{"rendered":"[Solved] What is a Combo Repository and a Service Bus?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-47114451\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"47114451\" data-parentid=\"47099152\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<blockquote>\n<p>I am thinking about using a NoSQL database to scale database reads<\/p>\n<\/blockquote>\n<p>Good idea. It sounds like you are going down the path of <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/martinfowler.com\/bliki\/CQRS.html\">Command Query Responsibility Segregation(CQRS)<\/a>. NoSql databases make for excellent read stores.<\/p>\n<p>The <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/enterprisecraftsmanship.com\/2015\/05\/06\/combining-sql-server-and-mongodb-using-nhibernate\/\">link<\/a> you referenced describes a technique to update<br \/>\nCombining SQL Server and MongoDB using NHibernate &#8211; this is what I meant by &#8216;Combo&#8217; (combining) Repository. &#8220;Combo Repository&#8221; isn&#8217;t a standard pattern. Quoting the author:<\/p>\n<blockquote>\n<p>Of course, theoretically, we could just move all the data to some NoSQL storage, but what if we don\u2019t want to get rid of our relational database completely? How can we <strong>combine<\/strong> them together?<\/p>\n<\/blockquote>\n<p>You&#8217;ve tagged your original question with both a <code>Sql-Server<\/code> and a <code>NoSql<\/code> database, so at a guess you&#8217;re in the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/martinfowler.com\/bliki\/PolyglotPersistence.html\">Polyglot space<\/a><\/p>\n<p>The <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/martinfowler.com\/eaaCatalog\/repository.html\">Repository Pattern<\/a> is a very common abstraction layer around data persistence.<\/p>\n<p>The &#8220;combining&#8221; link you&#8217;ve referenced specifically solves the problem of many-to-many relationships (often referred to as Junction tables in Sql), and the performance implications when there are many such relations.<\/p>\n<p>In the more general sense, as an alternative to providing interception points in NHibernate, you may \/ may not have abstracted data access via the repository pattern.<\/p>\n<p>Here&#8217;s an ultra simple (and non-generic) repository interface in C#:<\/p>\n<pre><code>public interface IWidgetRepository\n{\n     Task&lt;Widget&gt; FetchWidget(string widgetKey);\n     Task SaveWidget(Widget toBeSaved);\n}   \n<\/code><\/pre>\n<p>Suppose we already have a SqlRepository:<\/p>\n<pre><code>public class SqlWidgetRepository : IWidgetRepository\n{\n     public async Task&lt;Widget&gt; FetchWidget(string widgetKey)\n     {\n         ... Code to use Obtain an NHibernate session and retrieve and deserialize Widget\n     }\n    ... Other methods here\n}   \n<\/code><\/pre>\n<p>You could also choose to provide a <code>MongoDb<\/code> implementation<\/p>\n<pre><code>public class MongoWidgetRepository : IWidgetRepository\n{\n     public async Task&lt;Widget&gt; FetchWidget(string widgetKey)\n     {\n        ... Code to connect to a MongoDb secondary and Find() the \n           widget and deserialiaze into Widget\n     }\n    ... Other methods here\n}   \n<\/code><\/pre>\n<p>And to maintain both databases simultaneously, here&#8217;s an example of how this &#8220;combo&#8221; repository may look:<\/p>\n<pre><code>public class ComboWidgetRepository : IWidgetRepository\n{\n     private readonly IWidgetRepository _repo1;\n     private readonly IWidgetRepository _repo2;\n\n     public ComboWidgetRepository(IWidgetRepository repo1, IWidgetRepository repo2)\n     {\n          repo1 = repo1;\n          repo1 = repo2;\n     }\n\n     public async Task&lt;Widget&gt; FetchWidget(string widgetKey)\n     {\n          \/\/ Just need the one ... first one wins\n          return await Task.WhenAny(repo1.FetchWidget(widgetKey), \n                                    repo2.FetchWidget(widgetKey));\n     }\n\n     public async Task SaveWidget(Widget toBeSaved)\n     {\n          \/\/ Need both to be saved\n          await Task.WhenAll(repo1.SaveWidget(toBeSaved), \n                             repo2.SaveWidget(toBeSaved));\n     }\n<\/code><\/pre>\n<p>The above &#8220;combo&#8221; repository may well fulfil the needs of a single system (and there are many other ways to keep two databases synchronized).<\/p>\n<p>CQRS is however frequently used at enterprise scale (i.e. where you have many systems, with many databases).<\/p>\n<p>My comment about an <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/en.wikipedia.org\/wiki\/Enterprise_service_bus\">Enterprise Service Bus<\/a> will only make sense if you need to distribute data across an enterprise.<\/p>\n<p>The concept is simple<\/p>\n<ul>\n<li>Commands are queued to a transactional system (e.g. &#8220;Add Widget&#8221;) across the bus.<\/li>\n<li>Your system handling widgets performs the transaction (e.g. inserts the widget into a database)<\/li>\n<li>The <code>Widget<\/code> system then publishes (broadcasts) a message to the bus detailing that a new widget has been added (with all the relevant widget information)<\/li>\n<li>Other systems on in the enterprise which are interested in updates to Widgets subscribe to this message and will update their own <code>Read Store<\/code> representations of the Widgets (e.g. into a NoSql database or cache, and in the format which makes most sense to them).<\/li>\n<li>This way, when a user accesses any of these other systems and views a screen about &#8216;Widgets&#8217;, the system can serve the data from its own Read Store, instead of having to request the data from the <code>Widget<\/code> system itself.<\/li>\n<\/ul>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">4<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved What is a Combo Repository and a Service Bus? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I am thinking about using a NoSQL database to scale database reads Good idea. It sounds like you are going down the path of Command Query Responsibility Segregation(CQRS). NoSql databases make for excellent read stores. The link you referenced describes a technique to update Combining SQL Server and MongoDB using NHibernate &#8211; this is &#8230; <a title=\"[Solved] What is a Combo Repository and a Service Bus?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\" aria-label=\"More on [Solved] What is a Combo Repository and a Service Bus?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[3406,2690],"class_list":["post-12541","post","type-post","status-publish","format-standard","hentry","category-solved","tag-amazon-dynamodb","tag-nosql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] What is a Combo Repository and a Service Bus? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] What is a Combo Repository and a Service Bus? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I am thinking about using a NoSQL database to scale database reads Good idea. It sounds like you are going down the path of Command Query Responsibility Segregation(CQRS). NoSql databases make for excellent read stores. The link you referenced describes a technique to update Combining SQL Server and MongoDB using NHibernate &#8211; this is ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-30T20:53:00+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] What is a Combo Repository and a Service Bus?\",\"datePublished\":\"2022-09-30T20:53:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\"},\"wordCount\":464,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"amazon-dynamodb\",\"nosql\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\",\"name\":\"[Solved] What is a Combo Repository and a Service Bus? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-30T20:53:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] What is a Combo Repository and a Service Bus?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] What is a Combo Repository and a Service Bus? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] What is a Combo Repository and a Service Bus? - JassWeb","og_description":"[ad_1] I am thinking about using a NoSQL database to scale database reads Good idea. It sounds like you are going down the path of Command Query Responsibility Segregation(CQRS). NoSql databases make for excellent read stores. The link you referenced describes a technique to update Combining SQL Server and MongoDB using NHibernate &#8211; this is ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/","og_site_name":"JassWeb","article_published_time":"2022-09-30T20:53:00+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] What is a Combo Repository and a Service Bus?","datePublished":"2022-09-30T20:53:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/"},"wordCount":464,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["amazon-dynamodb","nosql"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/","url":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/","name":"[Solved] What is a Combo Repository and a Service Bus? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-30T20:53:00+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-a-combo-repository-and-a-service-bus\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] What is a Combo Repository and a Service Bus?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=12541"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12541\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=12541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=12541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=12541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}