Feature Flags In .NET + How I Use Them For A/B Testing

  Рет қаралды 15,396

Milan Jovanović

Milan Jovanović

Күн бұрын

☄️ Master the Modular Monolith Architecture: bit.ly/3SXlzSt
📌 Accelerate your Clean Architecture skills: bit.ly/3PupkOJ
🚀 Support me on Patreon to access the source code: / milanjovanovic
What are feature flags? You can think of feature flags as a switch that controls a specific application feature. When the feature flag is turned on, the related feature is active. The opposite also applies. Feature flagging in .NET is easy, and I'll show you how to implement it. As a bonus, I'll show you how I'm using feature flags on my website to run A/B testing (also known as split testing).
Join my weekly .NET newsletter:
www.milanjovanovic.tech
Read my Blog here:
www.milanjovanovic.tech/blog
Chapters
0:00 Adding the Microsoft.FeatureManagement library
0:57 Defining the first feature flag
2:02 Using the feature flags with IFeatureManager
6:56 Gradual feature rollout with PercentageFilter
10:30 How I'm doing A/B testing with Posthog

Пікірлер: 76
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
If you want to accelerate your .NET and software architecture skills, consider joining The .NET Weekly - my newsletter with 28k+ engineers. Subscribe here → www.milanjovanovic.tech
@LilPozzer
@LilPozzer 6 ай бұрын
It looks so cumbersome, if you have 999 features, one is related to mapping, another to business layer, it would look like lots of ifs all over the place
@MilanJovanovicTech
@MilanJovanovicTech 6 ай бұрын
That's the price
@upulwaruna.abeysinghe
@upulwaruna.abeysinghe 10 ай бұрын
Thanks for this content and new features, awesome and i am planning to use for my next project..thanks and love it
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
You're very welcome!
@kodindoyannick5328
@kodindoyannick5328 4 ай бұрын
Very useful content. Thanks Milan.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Glad it was helpful!
@taner-saydam
@taner-saydam 10 ай бұрын
It's a really useful feature. Thanks for the video.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Glad it was helpful!
@fieryscorpion
@fieryscorpion 10 ай бұрын
Great video. Thank you!
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Glad you liked it!
@genadyshmunik6041
@genadyshmunik6041 10 ай бұрын
Really nice example
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Glad you think so!
@ologungbaradavid2181
@ologungbaradavid2181 10 ай бұрын
You might need to find a way to put on the video that this is for a usecase where you need more than ON-OFF switch for a feature. Enjoyed the video. on to the next one.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
The smart ones will figure it out 😁
@alexmadnix
@alexmadnix 10 ай бұрын
감사합니다.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
물론이죠 Google Translate says this is "you are welcome" In any case, thank you so much for the support! ❤️
@antonmartyniuk
@antonmartyniuk 10 ай бұрын
Really nice call on the frontend and posthog. Something might be useful to me. And I see you like using tailwindcss too, really cool css framework
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
They have a very generous free plan, worth checking out for sure. And yeah, TailwindCSS rocks 😁
@antonmartyniuk
@antonmartyniuk 10 ай бұрын
@@MilanJovanovicTechtell me by secret: is the free tier enough for your website?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
@@antonmartyniuk Oh yeah. You can use the free tier and they will give you an estimate of your usage after a week based on your traffic. I'm nowhere near the 1M limits 😅 And I have about ~60-80k visits per month
@NuvemTreinamentos
@NuvemTreinamentos 2 ай бұрын
Great content! 👏 How would you control the flags per environment in the first approach (config file)?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
I'd probably move them to Azure App Configuration
@yurashkraba3042
@yurashkraba3042 10 ай бұрын
Hi Milan, Thanks for the video! I have a question regarding managing database changes. Specifically, if you applied an Entity Framework Core migration during the release and then updated some values in DB. I am just curious, how would you undo those changes in case a bug is found in the production environment? This is especially relevant if there isn't a staging environment or if the bug is only reproducible in production. I know, it should not happen in the prod but always something can happen
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
You can't undo database changes that easily, so this is something that needs to be planned very carefully. Essentially, if you keep your DB changes non-destructive, you will be able to revert the migrations.
@HamidNoahdi
@HamidNoahdi 9 ай бұрын
Thanks for your great video Milan. You are using antoher service for Front-End feature management. What if the websites wants to align the UI with the features available in Back-End. How should website gets the features available from Back-End or even from a specific user?
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
You'd use the same Feature Flag services on both ends.
@dawitdemissie4611
@dawitdemissie4611 10 ай бұрын
Thank you ! What is its advantage over using "IConfiguration" and read directly from the appSettings ?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
For simple on-off switch, you will probably be fine. But feature flags are much more powerful, when you need feature filters and targeting.
@balamurugankalyanasundaram426
@balamurugankalyanasundaram426 10 ай бұрын
Good one Milan. Is there a way to change the Featureflag value in production without redeploying the code when third party tools like Posthog not used?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Yes, you can use Azure Config manager or some other service like LaunchDarkly, Optimizely
@yardeZ93
@yardeZ93 9 ай бұрын
Hi Milan, Thanks for the video. What if I want the feature flags to be stored on a DB or a distributed key value store so I can change feature flags states without restarting the service? can I achieve that with that package?
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
You can use something like Azure App Config, and yes you can update feature flags without restarting the backend
@bayobizzle
@bayobizzle 10 ай бұрын
When you make changes to the efcore models that would also necessitate updating the database tables, how do you feature flag so that even though the code is deployed, the change to the models is not released until you switch on the flag? I assume that for features that does something in different ways e.g calculating tax, one would create new methods instead of mutating existing ones and then use the feature flag at the handler level to choose the appropriate method. This begs the question that in real world, you might need to create a new modified copy instead of mutating existing code?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
1 - You wouldn't control the migration with a feature flag, that's something that should be done manually 2 - Some duplication is expected, depending on how high or low level you want to place the feature flag check
@m5s10
@m5s10 10 ай бұрын
We used somewhat simplified version of this in my previous job. We kept the feature flags in database. In that case, you get all the benefits, but you can also change the system behavior in real time because you only need to make a db change in order for the flags to be updated. What would be the upsides of your approach compared to what we've done?
@sephirot7581
@sephirot7581 10 ай бұрын
Like he said, that are some funtionalities are already builtin like the percentage and or make sure that a service will remember if a user should see the feature or not. You coud also easily use this approach showed here with a database because its relies on config management from Dotnet which also allows to read from a database
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
My approach would be faster since it's reading from config files and not the database. But if you cache the flags, then it's even. You would also be missing out on feature filters and user targeting, so you will have to roll your own. The one I'm using for the website is pretty advanced and offers all of that, but it doesn't have a .NET SDK.
@RaZziaN1
@RaZziaN1 10 ай бұрын
@@MilanJovanovicTech Your answer sounds really cocky. Kind of rude.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
@@RaZziaN1 If you think this is cocky, you're too easily offended 🤣
@MsbowElite
@MsbowElite 9 ай бұрын
Feature flag in DB is costly and bring problems of handling the state and caching of the data, but everything depends on how it was implemented and what result you want. Usually resolving problems using less resources and simpler implementations are more compatible to a general purpose.
@ee-ns2ww
@ee-ns2ww 7 ай бұрын
How is this any better then having a simple flag in the config for lets say dev mode? or on/off. if this comes to having to manualy ask if the feature is enabled or not?
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
Because you can connect it to a confog source that can be dynamically configured. For example, which set of users can see the feature
@JonathanPeel
@JonathanPeel 10 ай бұрын
If we are not looking for the AB testing, do you think we could do this with something like Option?
@sephirot7581
@sephirot7581 10 ай бұрын
Yes and no. When it just comes for checking if something is enabled or not, then you can easily use Options but if you want more functionality like showed in this video, this not possible with just bare Options. You would need to implement by yourself
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
If all you need is an on/off switch, then you'll probably be fine. But I would still opt for feature flags in case I will need anything more advanced in the future.
@andriyliulka1121
@andriyliulka1121 10 ай бұрын
Hi Milan, What do you think about making video about IdentityServer4 and implementing separate Identity server by using this library ?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
How do we connect these?
@nagibatorbatcka86
@nagibatorbatcka86 10 ай бұрын
​@@MilanJovanovicTech I guess just by creating separate Identity server via IdentityServer4 library. Or it is not good approach in your opinion ?
@venussmodzhd1886
@venussmodzhd1886 10 ай бұрын
Do you know if we can use a database instead of appsettings?
@fieryscorpion
@fieryscorpion 10 ай бұрын
@@MilanJovanovicTech Thank you. That was great!
@sixtoortega138
@sixtoortega138 10 ай бұрын
Hi Milan, I'm confused, don't you think that this aproach could be achieve it using env vars instead of this package? I'm trying to implement the minor code as possible :) It's just a question, I like your video Cheers
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
For a simple on-off switch is possible it will be fine. But feature flags are much more advanced with feature filters, and the ability to pull the flags from different configuration providers.
@sixtoortega138
@sixtoortega138 10 ай бұрын
@@MilanJovanovicTech Thanks
@Hello_there_777
@Hello_there_777 10 ай бұрын
Hi. Do you know how to enable some feature only for users which have some specific role?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Yes - you need to explore Targeting - github.com/microsoft/FeatureManagement-Dotnet#targeting And take a look at this: github.com/microsoft/FeatureManagement-Dotnet/blob/main/examples/FeatureFlagDemo/HttpContextTargetingContextAccessor.cs Basically, you can target the user's by their role assuming they are present as claims on the IClaimsPrincipal (which is populated from a JWT for example)
@Hello_there_777
@Hello_there_777 10 ай бұрын
​@@MilanJovanovicTech❤
@pedromota9876
@pedromota9876 4 ай бұрын
Do you have a video with Feature Flags using Portal Azure / Feature Manager?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Nope
@alexmadnix
@alexmadnix 10 ай бұрын
👍👍👍
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
💪
@cyrildouglas9262
@cyrildouglas9262 10 ай бұрын
Any plans to make tutorials on Blazor?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
I heard you, recording one tomorrow, and coming out next week. It'll be more about SignalR though, but I'll connect it to a Blazor client. And I'll work on more Blazor content in the future.
@cyrildouglas9262
@cyrildouglas9262 10 ай бұрын
@@MilanJovanovicTech That will be great, thank you so much for your efforts.
@GeorgeMan-ks3xu
@GeorgeMan-ks3xu 10 ай бұрын
I don't know why should I use this instead of IOptions.
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Because you can configure feature filters for targeting specific users, roles, geographies. Try doing that with IOptions.
@thimok22
@thimok22 10 ай бұрын
Feature flags can definitely be a great option. However, how do you manage the extra overhead? 1. Once a feature is completely rolled out, you would want to remove the feature flag from the .NET code. So you have to remove it from the appsettings and all the extra if-statements, possibly the injections of the FeatureManager if no other feature flags are in the class. This greatly increases work. 2. Your example is an easy one. However, for example if you are working on a big feature, which not only contains a change in the code, but also say a layout change, it can get messy and ugly pretty quickly, and also create much extra overhead. How do you manage this cleanly?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
1. First step is to turn the feature flag ON for all users 2. You can then start cleaning up your code This is pretty standard with trunk-based development.
@techpc5453
@techpc5453 9 ай бұрын
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
A Very Elegant Way to Write C# Code - Switch Expressions
0:34
Milan Jovanović
Рет қаралды 13 М.
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 54 МЛН
Alat Seru Penolong untuk Mimpi Indah Bayi!
00:31
Let's GLOW! Indonesian
Рет қаралды 16 МЛН
50 YouTubers Fight For $1,000,000
41:27
MrBeast
Рет қаралды 63 МЛН
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 16 МЛН
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 82 М.
Don't Use Polly in .NET Directly. Use this instead!
14:58
Nick Chapsas
Рет қаралды 51 М.
Enforcing Architecture in .NET with tests
23:32
LaylaCodesIt
Рет қаралды 1,4 М.
Forget Controllers and Minimal APIs in .NET!
14:07
Nick Chapsas
Рет қаралды 58 М.
The RIGHT Way To Use HttpClient In .NET
11:46
Milan Jovanović
Рет қаралды 53 М.
Feature Flags are more than just Toggles
9:12
CodeOpinion
Рет қаралды 10 М.
Onion Architecture vs Clean Architecture Comparison
13:44
Milan Jovanović
Рет қаралды 37 М.
Самый дорогой кабель Apple
0:37
Romancev768
Рет қаралды 352 М.
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 5 МЛН
Мой инст: denkiselef. Как забрать телефон через экран.
0:54
Опять съемные крышки в смартфонах? #cmf
0:50
В России ускорили интернет в 1000 раз
0:18
Короче, новости
Рет қаралды 1,9 МЛН