Home > Articles > Details

Software Best Practices Learned by Experience

[8/16/22]: The best way to Call a Web API from C-Sharp



[6/25/22]:
When developing a highly scalable and performant application, think about what data is going to travel on the wire from your Server to the Client (person accessing the web page). Have empathy, care for the user, and put yourself in the user's shoes.

[Rule of Thumb]: Return only necessary data, look into the HTTP Response Payload and remove some of the data not needed for that specific request.
- remove unnecessary cookies, javascript, any processing compute needed to return the response, and unnecessary images, and make sure you are caching appropriately.
- Always verify, DO NOT ASSUME things are working right.
- Pay extra attention to Memory Allocation, every time you want to create a new object think again, and again. Think about different ways to solve the problem without creating an Object to keep track of what you are doing. If you are developing in C-Sharp looking for how you could use Span and Array Sharing to avoid allocation.

- Be aware of 1st, 2nd, and 3rd generation Memory Allocation, Heap vs Stack. This will help you understand Allocation and when the Garbage Collector kicks in
   to collect Stale Objects.

- Know the Life Cycle of the Object you just created, when does it get collected by a Garbage Collector? when you create a new object, does it get allocated
   on the Heap or Stack? does it linger a while before it is disposed of?

- Know where your resources like images and data from the database are, and what your infrastructure looks like. Be frugal in terms of how you call the database, and use resources (do you retrieve or call the database every time the request hits your Server?).

Ask questions:
1. Are the images on #SASS or #SSD Drives? is the #CDN involved in this architecture? what is the Cache Period for this resource?
2. Where is the #Database located? is there a Load #Balancer to help hit the nearest Database Server?
3. Is there any Caching Middleware in place, how do we think performance in this case?
4. When the request hits the server, do you think about returning the response as soon as possible without halting that request?

     - Identify the Hot Path, the code execution route many requests take and eliminate unnecessary computing or processing
            - I mean, if you have an operation that massages the request or retrieves a big blob of data from someone on every request.
              Think about how you could optimize that Hot Path.

5. What is the Internet Speed of the Datacenter this application is going to be hosted?


Ask questions:
1. If this user was me, how would I like the web page to perform when browsing
2. How would I rate my experience when interacting with the page?
3. Would I like to see popups, if yes what information would I like to see in that popup?


Asking the questions above will help evaluate some of the architecture decisions and Software Good Practices to implement.

[6/22/22]: Writing to the Database and Saving Changes
1. when writing to the database using Entity Framework Core 6.0, you need to Save Changes while you are still in the current function, otherwise, when you try to Save Changes when you get out of the function and in another class the EF Core Change Tracker does not detect changes and item won't be saved in the database.

- Rule of thumb though, keep in mind that when you use Async Await do not combine any Async with Async function calls.



[9/20/21]: If you are developing business logic, do not scatter code that does merely the same all over the application. Find one file that is responsible for one task and break up big functions into smaller manageable functions.

- Case in thought: I spent  4hours trying to find what is causing a redirect to another page in a legacy code base. Not cool man!



If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy