Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developer power-up: essential Couchbase SDK patterns for getting started quickly – Couchbase Connect New York 2017


Published on

New to Couchbase or NoSQL in general? Wondering how to get started? Join this session to get up to speed quickly with the essential concepts. Learn how Couchbase’s data platform builds on top of the NoSQL basics and provides powerful services for developers to tap into for accelerated application development. Learn how you can start to use these services and APIs right away, with minimal coding and targeting many of the common application programming patterns.
Hear from Brant Burnett, systems architect at CenterEdge Software and recognized Couchbase Expert, on how to use LINQ and .NET to seamlessly transition your existing SQL and application development skills and knowledge to Couchbase Server. Learn how easy NoSQL can be with the help of Couchbase, N1QL, and LINQ.

Published in: Software
  • Check the source ⇒ ⇐ This site is really helped me out gave me relief from headaches. Good luck!
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Developer power-up: essential Couchbase SDK patterns for getting started quickly – Couchbase Connect New York 2017

  1. 1. ©2016 Couchbase Inc.©2016 Couchbase Inc. 1 Brant Burnett Systems Architect Couchbase Expert
  2. 2. ©2016 Couchbase Inc.©2016 Couchbase Inc. About CenterEdge Software  Point of Sale  Admissions & Ticketing  Party, Group & Event Bookings  Online Sales & Party Reservations  Time Clock & Labor Management  & More! 2
  3. 3. ©2016 Couchbase Inc.©2016 Couchbase Inc. About CenterEdge Software • Celebrating 13 Year Anniversary • Team of 60 in Roxboro, NC • Sister company is Palace Pointe, a 100k sq. ft. Entertainment Venue for which we were developed as an in- house system • Over 700 facilities using our platform around the world • FEC’s, Waterparks, Trampoline Parks, Amusement Parks, Skating Rinks, Bowling Centers, Zoos & Museums 3
  4. 4. ©2016 Couchbase Inc.©2016 Couchbase Inc. CenterEdge and Couchbase FirstYear Using Couchbase Server 2012 4 FirstVersion Of Couchbase Server 1.8 Couchbase Server Production Clusters 2 Couchbase Server Production Nodes 10
  5. 5. ©2016 Couchbase Inc.©2016 Couchbase Inc. CenterEdge Cloud Data Flow Architecture 5 Data Data Data IndexQuery Services On Premise Application Servers
  6. 6. ©2016 Couchbase Inc.©2016 Couchbase Inc. Why Couchbase For CenterEdge’s Newest Cloud Platform? • More scalable and performant than traditional SQL in the cloud • Previous online store system uses 21 SQL servers, each hosting 30 stores • Since each store is only on a single server, it doesn’t handle spikes in load efficiently • Servers can’t be scaled vertically without downtime for all 30 stores on that server • Schema-less JSON increases flexibility as your system evolves, leaving schema enforcement in your data access layer • Schema changes to large tables can result in downtime as data structure is updated across all records • We were already using Couchbase for our shopping carts as well as a SQL caching layer, with great success. Now we can simplify the architecture with a single data layer. 6
  7. 7. ©2016 Couchbase Inc.©2016 Couchbase Inc. FindingThe Right Tool For The Job 7 Microservices allow the transparent use of different tools, languages, and stacks
  8. 8. ©2016 Couchbase Inc.©2016 Couchbase Inc. Language and Platform Agnostic = Flexibility 8 Couchbase Cluster Monolithic Windows Application Serverless Functions .NET Core Docker Microservices
  9. 9. ©2016 Couchbase Inc.©2016 Couchbase Inc. But my team doesn’t know NoSQL… 9
  10. 10. ©2016 Couchbase Inc.©2016 Couchbase Inc. LINQ2Couchbase • Provides easy N1QL query generation and execution using LINQ • Includes many advanced functions like nested objects and arrays • Open source project • Managed by Couchbase • Supported by the Couchbase Community • • 10
  11. 11. ©2016 Couchbase Inc.©2016 Couchbase Inc. Easy Queries = Improved Productivity 11 public ActionResult BasicQuery() { var db = new BucketContext(ClusterHelper.GetBucket("travel-sample")); var query = from p in db.Query<Airline>() orderby p.Name select p; return View(query); } SELECT `Extent1`.* FROM `travel-sample` as `Extent1` WHERE (`Extent1`.`type` = 'airline') ORDER BY `Extent1`.`name` ASC
  12. 12. ©2016 Couchbase Inc.©2016 Couchbase Inc. POCOs For LINQ2Couchbase 12 [DocumentTypeFilter(TypeString)] public class Airline { public const string TypeString = "airline"; public string Callsign { get; set; } public string Country { get; set; } [JsonProperty("iata")] public string IATA { get; set; } [JsonProperty("iaco")] public string IACO { get; set; } public int Id { get; set; } public string Name { get; set; } // Type is read only to maintain consistency public string Type => TypeString; } Key: airline_10 { "callsign": "MILE-AIR", "country": "United States", "iata": "Q5", "icao": "MLA", "id": 10, "name": "40-Mile Air", "type": "airline" } Note: DocumentTypeFilter automatically applies a WHERE type = ‘x’ predicate Making Type property read only ensures it’s always saved correctly
  13. 13. ©2016 Couchbase Inc.©2016 Couchbase Inc. Efficient Indexing Is Especially Important For Couchbase 13 /* Use predicate to only index documents of a certain type */ CREATE INDEX `airport_sourceairport` ON `travel-sample` (`sourceairport`) WHERE `type` = 'airport' /* To index the same attribute across multiple document types, include type attribute first */ CREATE INDEX `def_type_id` ON `travel-sample` (`type`, `id`) /* A good practice is to create a fallback in case other indexes aren't used */ CREATE INDEX `def_type` ON `travel-sample` (`type`) If you’re using the “type” attribute as the logical equivalent of a table in SQL, most indexes will include this attribute.
  14. 14. ©2016 Couchbase Inc.©2016 Couchbase Inc. Working With Date/Times • Date/Times are usually stored as ISO 8601 strings or Unix timestamps in JSON • ISO 8601 is more human readable, Unix timestamps are easier to use • Some people simply store both in the document • Use STR_TO_MILLIS(x) in indexes and queries to work with ISO 8601 strings 14 /* STR_TO_MILLIS converts an ISO8601 string to a Unix numeric representation */ /* It also handles the time zone specifier */ SELECT `Extent1`.* FROM `beer-sample` as `Extent1` WHERE (`type` = 'beer') AND (STR_TO_MILLIS(`Extent1`.`updated`) <= STR_TO_MILLIS("2010-01-01T00:00:00Z")) /* STR_TO_MILLIS must also be used in the index, or the index cannot be used */ CREATE INDEX `beer_updated` ON `beer-sample` (STR_TO_MILLIS(`updated`)) WHERE `type` = 'beer'
  15. 15. ©2016 Couchbase Inc.©2016 Couchbase Inc. Lots of Power! 15 public ActionResult Join() { var db = new BucketContext(ClusterHelper.GetBucket("travel-sample")); var query = from route in db.Query<Route>() join airline in db.Query<Airline>() on route.AirlineId equals N1QlFunctions.Key(airline) where route.SourceAirport == "ATL" && route.DestinationAirport == "ABE" orderby airline.Name, route.Stops select new RouteModel { AirlineName = airline.Name, Stops = route.Stops, Schedule = route.Schedule }; return View(query); }
  16. 16. ©2016 Couchbase Inc.©2016 Couchbase Inc. Querying is nice, but I like to change stuff… 16
  17. 17. ©2016 Couchbase Inc.©2016 Couchbase Inc. ChangeTracking! 17 _db.BeginChangeTracking(); // Query must return the document class, without a select projection var query = from p in _db.Query<Airline>() where p.Id == id select p; // Query must execute after call to BeginChangeTracking var airline = query.FirstOrDefault(); if (airline == null) { return HttpNotFound(); } airline.Name = model.Name; airline.Callsign = model.Callsign; // Save the changes, if any _db.SubmitChanges();
  18. 18. ©2016 Couchbase Inc.©2016 Couchbase Inc. Update your models to support proxies 18 [DocumentTypeFilter(TypeString)] public class Route { public const string TypeString = "route"; // Read only property to return the calculated primary key // This is used when saving the document [Key] public string Key => TypeString + "_" + Id; // Properties must be virtual for changes to be tracked public virtual string Airline { get; set; } // some properties not shown for clarity... // Lists now use IList<T> instead of List<T> public virtual IList<Schedule> Schedule { get; set; } // some properties not shown for clarity... public string Type => TypeString; }
  19. 19. ©2016 Couchbase Inc.©2016 Couchbase Inc. Lions andTigers and NOTransactions, Oh My! 19 • My greatest fear in moving from RDBMS was losing two-phase commits (a.k.a. the ACID transaction) • When using Microservices, 2PC is a problem even with RDBMS • Using a DistributedTransactionCoordinator introduces complexity, reduces perf, and adds a point of failure • Instead, consider each Microservice = a Domain • Design communication between Domains so that transactions aren’t required • Message Bus, Event Sourcing, etc. • Great presentation by Chris Richardson at DevNexus
  20. 20. ©2016 Couchbase Inc.©2016 Couchbase Inc. Couchbase + Domain Driven Design + Microservice = Great Marriage 20