PAWIT.PW

My dedicated space, focusing on Power Apps and other Power Platform stuff 😉

How I built complex Power Apps with less performance impact

Greetings

Howdy everyone! Today I will share what I learned from my last project experience, Yes, it’s a Power Apps project, I can called this is the most complex Power Apps I ever built.


Brief

Well, This app is designed for trading company who managed both sales process, warehouse process, transport process themselves, They have their own sales person, warehouse worker and fleet transport.

The all party above is the user of the app, So, year… this app is gonna be a complex apps that contains many modules.


Functional Requirements

There are tons of functional requirement.. but here is list of remarkable

  • Sales person can check customer’s data and status
  • Sales person can create sales order
  • Sales person can check related promotion & discount
  • Sales person can do billing and payment collection process
  • Backoffice can release sales order to warehouse worker
  • Warehouse worker can see a task they need to do
  • Warehouse worker will know what to pick for each order
  • Warehouse worker can recheck all item in the box with the order
  • Transporter can see a delivery they need to do
  • Transporter can track which box is deliveried or need to send back to warehouse
  • The app need to support mobile, web, desktop
  • The app need to seamlessly integrated with Dynamics 365 Finance & Operations (in short, D365 F&O)

Technical Requirements

Now its my turn! Let’s dive into things we like. A technical things.

  • This app need to built on Power Platform (for quick development & maintainability & security reason)
  • This app will have ~100 concurrent users.
  • This app need to handle transaction that come in almost every second.
  • This app need to real-time integrated data from Dynamics 365 Finance & Operations.
  • This app need to connect more than 50 tables / data source.
  • This app need to handle large data source (such as master data of customer which have ~300,000 records…)
  • This app need to be fast (even when searching on large datasets)

At this point you may think that seem to be basic, nothing hard. But here is a fact: The big issues is the performance..

Microsoft say more data source connect to the app, more resource consuming it will be, and our app have 50+ tables…

This result in multiple technique involve in this single app as below!


Software Architecture

This architecture show how the app integrate with D365 F&O

  • Dataverse table – this store only large datasets (usually master data) that user need to perform a search quickly. Because actual data was stored on Dataverse and Dataverse have the fastest connection to Power Apps. Thanks to Dual-Write that allow us to archieve near real-time data update.
  • Dataverse Virtual Entities – This is the primary way we use, because it’s good performance, fast query speed (still slower than actual Dataverse) and the main reason is it’s easy to maintain.
  • Power Automate – Power Apps can’t perform some operation to D365 F&O. So we need to use help of Power Automate, and the benefit is we have log about what our user is doing (e.g. when they create sales order)
  • Fins & Ops – Even using every integration way above that allow Power Apps to query data in D365 F&O. There are one thing that impossible for Power Apps like extremely complex query, some operation in D365 F&O have very complex query (e.g. calculating customer credit limit balance) that need to query from 10+ tables and countless lines of X++ code in D365 F&O side, So. It’s better to lets D365 F&O do that and just return a result to Power Apps, we can do this using “Execute action” connector to call X++ code in D365 F&O

The App

This app now have 40+ screen (and more will be added). At this point I can say that it “not that easy” to maintain this app.

Changing or modify some function on one screen shouldn’t break / effect other screen while some part of the app that use the same template should have same look and functionalities (e.g. popup, modal)

And the hardest part, It need to be “maintainable”

The key to archieve this are

  1. Context variables: Unlike global variables, context is limited to screen, this mean each screen will only have related variables, variables that not relate or effect with current screen will not appear. This make is easier to code without getting confused. (Context can be passed through screen when Navigate)
  2. Component: We usually have some part of the app that have the same looks and functionalities like popup, modal or hamburger menu. We should use component for this, because you will ensure that its the same in every part of your app, and when you need to modify, just modify once and it will take effect everywhere.
  3. DO NOT reference control across screen: This is the most important things. Because when you’re on Screen2 and try to get value of TextInput in Screen1, Power Apps need to load both screen. Imagine you created 10+ screen with this, it will result in infinite chain, This is huge performance impact.
  4. Use Dataverse: If your app is buisness critical, have large datasets, require fast query time and easy to maintain. Dataverse have far away better performance with Power apps than all other connector. Don’t let the license cost block you out, If the app help your business, it always worth. Power Apps per App per User is just 5 USD/month/user, it not shown in Microsoft public site but can still order in Admin Center
  5. Always use Solutions: Solutions allow you to group related component like apps, flows, tables into single package. Easy to maintain, especially when you need to deploy to different environment: UAT, Production, etc. So ALWAYS USE SOLUTIONS.
    (I see a lot of app maker spend hour to manually import & export and then reconfig their app to Production while I use just 5 minutes using Solutions)
  6. Don’t put duplicate code everywhere: Its common that same functionalities may appear in many part of the app, may be in different screen, different button. The important things is DO NOT put duplicate code because it will be double-work especially when modifying it, There are a lot of way to avoid duplicate code like: put code in single hidden button and then all other button just select this button, use component.
  7. Use With() function: With function is a Power Fx function that can reduce duplicate code, it also make your code easier to read. Especially when you want to reference to the same calculated value within the same property of control, Instead of just putting duplicate calculation code, just use With function!
  8. Avoid increase collection limit: I know that many maker increase app’s collection limit from 500 to 2,000 records as “workaround” of delegation. But in fact, That’s too much and its degrading app performance, So. just stick with 500, It’s reasonable for both performance and usage.
  9. Delegation is important: Many maker don’t care about delegation warning (yellow warning sign). Yes, It not a problem when working with small datasets but a big problem when working with large datasets. I know that some connector has many limit on delegation (e.g. SharePoint) sometimes it can’t be avoid but you can filter with delegable function and non-delegable function in the last order.
  10. Use container: Instead of using code to referencing other control position/size, Just use container. It’s harder to arrange but it make your app pixel perfect with better auto layout assignment (I use contain in all my app, even it’s not responsive.

Result

So.. after complicate way of developing, more time consuming development, what we get?

  • Support all the requirement: This app support all the requirement stated above, while still archieve…
  • Fair-performance app: I will not say that it’s so fast or instant response but it’s fast enough for (most) user to not complaining about it
    (We get 1-2s query time when searching in tables with 300,000+ records, Even faster than in D365 F&O)
  • Maintainable app: I can say that if I send this app to another Power Apps, It will be not hard for them to track and modify it without breaking it. Because all the code appear in a place where it should be, no duplicate code, no mysterious code from Screen1 that break Screen2

Screenshots

That as a long post and long journey developing this app, Here is a result.


, , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *