This repository implements a targeting engine that routes campaigns to the right requests, with a focus on extensible, maintainable, and reusable code.
-
Start MySQL
brew services start mysql
-
Create the database and tables
mysql -u root -p < schema.sql
Targeting logic and dimension handling are decoupled, so you can add new dimensions easily without changing application code.
-
Dimension is stored as a VARCHAR, not an ENUM.
-
ENUM requires a schema change every time you add a new dimension.
-
VARCHAR allows arbitrary dimension names without DB migration.
INSERT INTO targeting_rules (campaign_id, dimension, type, value) VALUES ('spotify', 'DeviceType', 'INCLUDE', 'Tablet');
-
| Dimension | Required | Example Value |
|---|---|---|
app |
✅ | com.example.app |
country |
✅ | US |
os |
✅ | android |
devicetype |
Optional | tablet |
subscriptiontier |
Optional | premium |
-
Update the RequiredDimensions or OptionalDimensions list in delivery/config.go.
-
Add the corresponding targeting rules in the DB:
INSERT INTO targeting_rules (campaign_id, dimension, type, value) VALUES ('spotify', 'SubscriptionTier', 'INCLUDE', 'Premium');
-
In a service like this, if there are ~1000s of campaigns, thats KBs of data. And with 100000 of requests, thats still MBs of data. Adding an In-memory cache using the service's memory would be the fastest way to cache, as it will avoid the network hop required to query redis or anything.
-
But Since I am trying to make a production ready service, such a service can be deployed on multiple pods, which can be sharing cache. Its better to implement redis, which is what I will do :)