Predictive Text Fast Predictive Text using Azure Table
Predictive Text Fast Predictive Text using Azure Table Storage Copyright © 2016 Monza Cloud, LLC
Agenda • Who we are, Monza Cloud, LLC. • Note: We’re not here to read MSDN articles / code snippets to you. We’re here to demonstrate production code techniques and share lessons learned • How we use Caa. S (Configuration as a Service) with database driven configuration repositories • Quick introduction to Az. Studio, our cloud APIs and Tools • Demonstrate the basic steps to work with storage using MSDE code • Practical Demonstrations : • • Caa. S at work – Shortcuts and environments explained Blob storage creation, routing, and testing Queue creation, routing and testing. Demo Big. Item Table Storage creation, routing and testing. Demo Big. Item • Closing statement • Q&A, reference to resources
Monza Cloud, LLC • Founded in 2015 • Team worked for several years on various Azure projects before forming company • We specialize in rapid development of Saa. S offerings that take advantage of our Azure framework • We’re not a big “move this VM” or “Modify this existing app” team, we’re here to write your apps in the cloud for the cloud • Extensive experience deploying “internet of things” solutions
Az. Studio : Quick Overview • For today’s demos we’re using our the Monza Cloud product suite for Azure, Az. Studio • Az. Studio C# API’s == JQuery or Angular in the Java. Script world • Az. Studio == Visual toolset used by programmers and Dev. Ops • If you’re developing in Azure you WILL develop something like this in your environment. Either using a collection of tools / scripts or something consolidated like our product • You will use these patterns and codify them in your organization in order to survive the rapid decomposition of resources in a Saa. S / Paas Environment
What is Predictive Text? • Predictive Text maintains a dictionary of strings, when the user selects a key the dictionary is referenced to suggest full words the user intended to enter • This list can be simply an alphabetic list or it can be more sophisticated, ranking based on past user entries or grouped by similar meanings • As the user types, a short list of predicted final text is displayed • This list can be anything you organize. Bing’s search box is an extremely complex example of predictive text
Why Use Predictive Text? • • • User needs to select for a very large list of values User wants to select from a wide range of possible values You want to present context-weighted choices to the user The user does no know exactly what data is available Speed up the repeated, related, searches and activities Help handicap users and improve user experience on more limited input devices
Implementation: Outline • • • Set up and configure storage API objects Create a Table Storage API wrapping predictive search Implement source configuration plans Implement and deploy source indexing workers Implement a web service utilizing the above elements Test!
Common Pattern in Azure Storage • Create your storage account • Use connection string to connect to account, preserving this connection reference in memory (singleton pattern) • Get a reference to the storage type (blob, queue, table storage). Keep that reference in memory as well • Get a reference to the specific resource (container, queue client , table client). Yes, preserve the reference for future operations • Perform actions. Usingleton patterns will speed up subsequent steps dramatically. Using “infrequent refresh” techniques will allow you to update the above information without recycling roles
Table Storage Basics • Table storage is high-volume schema-less entity storage • Tables store any class that implements ITable. Entity, which has several restrictions • Two properties make up the primary key for a row Partition. Key and Row. Key • You can only really effectively query against these two keys. While you can query against any of you’re classes properties, not using these two properties will invoke a full table scan • Careful planning around keys is the core principle of using table storage • See https: //azure. microsoft. com/en-us/documentation/articles/storage -table-design-guide/#table-design-patterns for detailed pattern / antipattern information
Adding to Table • Whatever we do, it must use Partition or Row key in order to scale / be fast. • Thankfully, we’re allowed an unlimited number of partition keys. • In fact, the technology performs best the more partition keys we can create with smaller sets of row keys per partition • So, let’s take a look at our algorithm….
Code Snippet…. . Cloud. Table tbl = Get. Table. Reference(table. Shortcut. Name, federation. Key); if (tbl == null) { return; } Table. Operation insert. Operation = Table. Operation. Insert. Or. Replace(entity); tbl. Execute(insert. Operation); . . .
Adding to Table: Add 1 st Term
Add to Table: Add 2 nd Term
Add to Table: Final Table State
Remove Item • Generate partition keys as you do an ADD operation • Delete the set of rows, one for each partition keys • Keep in mind local caching layers should invalidate periodically to reflect the new change
Querying Storage • Basically, pass in the string to a service call • We always provide a prefix • Remember you can use prefixes to segment your query by entity (that is, make the query multi-tenant and / or multi-user) • TAKE directive is very necessary for speed
Querying Storage – Code Snippet Cloud. Table tbl = Get. Table. Reference(table. Shortcut. Name, federation. Key); Table. Operation op = Table. Operation. Retrieve<T>(partition. Key, row. Key); Table. Result tr = tbl. Execute(op); if (tr. Result != null) { return tr. Result as T; } else { return null; }
Live Demo Nothing beats a live demo!
Clearing the Table: Instant Table Clear • Normally a CLEAR() directive to a table only marks it invalid and asks Azure to clear (truncate? ) it at a later time • We don’t have any mechanism to tell when this process is complete or how long it might take • If you have implemented a abstraction pattern such as we have in Az. Studio (shortcuts) it’s possible to instantly clear an Azure Table in Table Storage • The trick is a real-time swap of the underlying container used to host the table • Your Table Storage API must be robust enough to invalidate and retry when it detects this scenario
Clearing a Table: Workflow
Live Demo – Quick Clear Table Nothing beats a live demo!
Conclusion • Table storage provides a surprisingly fast, scalable in inexpensive solution for suggestive search • Creative use of patterns when adding data can create powerful search order conditions • Using prefixes for partition keys gives you the ability to implement multiple searches in a single table • Prefixes can also be used to implement a per-user search • You can be creative, the indexing logic can be modified for powerful effect
- Slides: 22