mysql – Anonymous and Public User Table Design in twitter like application

I have schema design problem which I am not 100% sure if my assumptions are correct.

So the requirements are:

  1. I need to have 2 different type of user, anonymous and public.
  2. A user can have both anonymous and public profile.
  3. A public and anonymous user can follow anonymous and public.
  4. Anonymous user and public user must not be identifiable by clients. Which means if I know public user I shouldn’t be able to fetch anonymous profile details vice versa.

I first come up with idea:

User (id, anon_id,public_id)
AnonymousUser(id(PK,FK),nickname)
PublicUser(id(PK,FK),nickname,fullname,phone,is_phone_registered)
RelationShip(id,follower_id(FK-User),following_id(FK-User))
Tweet(id, author_id(FK-User),text)

In this design I could split users into two. However, if we know the tweet’s author id we are not able to understand if it’s send by public or anonymous account. And also the same problem exist in Relationship too, we are not able to understand if follower/following is anonymous or public. The solution might be adding 2 more fields to Relation clarify follower/following type ie. follower_type/following_type and 1 more field to Tweet author_type.

Another solution which I felt more correct is

User(id(PK),nickname,fullname,phone,is_phone_registered,public)

In this design I can have both anonymous and public profiles in same table. And records would look like:

id nickname fullname phone is_phone_registered public
123 slayer John Doe +1 90 123 123 12 12 true NULL
312 vendetta NULL NULL false 123

And public field should not be visible to clients so I am pretty much achieving my goals on security side of things.

Sorry for my ignorance I am having NoSql background and in sql world I feel like I need achieve:

  1. Single responsibility in tables
  2. Get rid of a lot of redundant null’s
  3. Feels like self referencing column is an anti-pattern, which is public field is referencing to other rows id.

All suggestions are welcomed.

versioning – Domain driven design model version

sorry for the long question, but I love DDD but there is a problem I can’t seem to resolve.

We have a problem when adding business rules to the aggregate root.

Our architecture is mostly like this when we make a query from the front-end :

For a simple example, we have a Book we want

  1. to persist
  2. fetch it.

The book has

Name which has to be 10 characters
and an Author which needs 15 characters.

Here the pseudo code in TypeScript:

class BookAggregateRoot {
   private _name: string;
   private _author: string;
   private constructor(name: string, author: string) {
       this._name= name;
       this._author= author;
   }

   static create(name: string, author: string): BookAggregateRoot {
       if(name.length < 10) {
           throw error; // not really throwing, its just to show we have an error
       }
       if(author.length < 15) {
           throw error; // not really throwing, its just to show we have an error
       }
       // all data is valid, create the Book
       return BookAggregateRoot(name, author);
   }
}

1st Scenario : save the book

Client -> DTO -> controllers -> useCases(1. calls create from Book
class) -> calls repositories(persist the data) -> database -> data is
returned, repositories(2. calls create from Book class) ->
useCases -> mapperToDTO-> controller -> client.

2nd Scenario : fetch the saved book

Fetching data is in the same way but only, dont need to persist, only
fetch the data : Client -> DTO -> controllers -> useCases(builds the
query) -> calls repositories(query) -> database -> repositories(3.
calls create from Book class) -> useCases -> mapperToDTO-> controller
-> client.

As long as the business rules don’t change, it’s fine as the data stored and the data fetched has the same business rules.

The problem lies in the creating of the AggregateRoot. Let’s say now my Book needs a publishedDate, all data that previously doesn’t satisfy the data fetched from the database and will fail at step 3.

The class now becomes :

class BookAggregateRoot {
   private _name: string;
   private _author: string;
   private _publishedDate: Date;
   private constructor(name: string, author: string, publishedDate: Date) {
       this._name= name;
       this._author= author;
       this._publishedDate = publishedDate;
   }

   static create(name: string, author: string, publishedDate: Date): BookAggregateRoot {
       if(name.length < 10) {
           throw error; // not really throwing, its just to show we have an error
       }
       if(author.length < 15) {
           throw error; // not really throwing, its just to show we have an error
       }
       if(publishedDate.invalid) {
           throw error; // not really throwing, its just to show we have an error
       }
       // all data is valid, create the Book
       return BookAggregateRoot(name, author, publishedDate);
   }
}

the data will always fail at step 3. above as the create requires a date.

We could create a migration to fix all the data… but is that the right approach?

thanx in advance and let me know if there is anything to better the design. 🙂

html – Visual Design Feedback on shopping cart experience

I am re-designing a shopping page experience, which is currently based on an OpenCart theme. I am seeking visual design feedback on the designs.

Some visual design changes in the redesign:

  • “Instead of a coupon” has a capital “I”. What is more appropriate – a lowercase or an uppercase?
  • An all uppercase item description – bold and fully justified. Ignore the actual words in the text, and focus only on the look and feel of the changes.

Current Design:

Current page

Proposed Design:

Proposed page

database design – ERD Help: While Designing a ER Diagram for a basic Car Rental system, Is the reservation entity weak? are all the relationships to this entity weak?

I am trying to design an ER diagram with the following conditions.

Entities and attributes:

CUSTOMER: The CUSTOMER entity holds all information about the customer. It must store customer name, customer ID, phone and physical address.

VEHICLE: The vehicle entity holds all about the car. It must store license plate, vehicle name, model number, vehicle type (SUV, Sedan, Minivan, etc.) and locations at which the vehicle is available.

LOCATION: The LOCATION entity holds all information about the physical address where the cars are available. It must store the location ID and physical address.

RESERVATION: The RESERVATION entity stores all the information about the reservation made by the customer. It must store details like reservation ID, customer ID, license plate, location ID, pickup date and return date.

Relationships:

Each customer might have zero or many reservations, but each reservation must have been made by one and only one customer.
• Each location may have zero or more reservations and each reservation must have one and only one location.
Each reservation must contain one and only one vehicle.
Each customer must have one and only one vehicle and each vehicle should be given to one and only one customer

Notes:
Please identify the primary and foreign keys in the entities.
Show associative entities where applicable.
Differentiate strong and weak relationships in the ER diagram using the appropriate representation.

Can someone please guide me here on creating this ERD

database design – Why if a transaction unlock a data item immediately after its final access of that data item, then serializability may not be ensured

The quote below is from Silberschatz’s Database System Concepts. It says if a transaction unlock a data item immediately after its final access of that data item, serializability may not be
ensured. Can you please explain why serializability may not be ensured?

Transaction Ti may unlock a data item that it had locked at some earlier point.
Note that a transaction must hold a lock on a data item as long as it accesses that
item. Moreover, it is not necessarily desirable for a transaction to unlock a data item
immediately after its final access of that data item, since serializability may not be
ensured.

html – Please critique proposed page design change

Here’s the current product page, which is based on an OpenCart theme that was purchased.

Current page

And here’s the page design that’s being proposed. Ignore the actual words in the text, and focus only on the look and feel of the changes. Also imagine that the fully justified 3 blocks of bold text are aligned left and right (I had trouble doing this in my image editing software).

Proposed page

Please let me know your criticisms of either the current design, or the new design changes. I’m really just looking for impressions, such as whether the current or the new one look more professional, or if something sticks out like a sore thumb.

Also, note that in the new design, “Instead of a coupon” has a capital “I”. It is important for me to know whether you think a lower case or upper case initial “I” is most appropriate.

machine learning – Is it bad design to pass around a dictionary of arguments to all your functions?

In my machine learning pipeline, I have all the arguments collected into a dictionary.

args = {'save_model': True,
'learning_rate': 0.01,
'batch_size': 4,
'model': 'my_model',
'momentum': 0.9,
'random_brighness': 0.5,
'random_flipping': 0.5,
...}

Then I have a bunch of functions that take the entire args dictionary as an input. Each of these only uses a small subset of all the arguments. Is there anything wrong with this design?

model = get_model(args)
data = get_data(args)
transformed_data = transform_data(data, args)

from the perspective of the function, it looks like:

def get_trainer(args):
loss_function = args('loss_function')
optimizer = args('optimizer')
class_weights = args('class_weights')
...

versus:

def get_trainer(loss_function, optimizer, class_weights)
...

design – The use case of materialized view

I have a use case that some external 3rd party vendor services send our service an item with price and a time range, the data schema includes :

vendor_id, item_id, price, time_range

it means the price for this item from this vendor is $price value during the time interval of time_range.

Our service needs to support

  • given a item id, query for all the vendors current price
  • given a future timestamp, item id, and vendor id, query for the price

I consider to create materialized view of the database because I don’t want to hit the database too frequently for a large amount of queries.

From the doc in oracle,

A materialized view is a replica of a target master from a single point in time. The master can be either a master table at a master site or a master materialized view at a materialized view site. Whereas in multimaster replication tables are continuously updated by other master sites, materialized views are updated from one or more masters through individual batch updates, known as a refreshes, from a single master site or master materialized view site,

It looks like I just create a table locally in memory and it’s a “copy” of the remote database. The concerns of using view are:

  • it takes much memory usage, and
  • because the database is updated often with different vendor new feed, and it is updated when the price is invalid (out of the time range), using materialized view means I have to refresh often to get the latest view, so it will not reduce network loads as mentioned in pros of materialized view.

None of the two concerns above is listed as potential cons of materialized view. Does it still fit for my use case then?

design – All the properties of a domain object should support NULL value?

Imagine you have an application with the domain object User:

public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Surname { get; set; }
        public bool Premium { get; set; }
        public int OrdersNumber { get; set; }
    }

Your application has 3 views:

  • the first one must show id, name and surname of all the users
  • the second one must show name and surname of a user, and if he’s a premium user
  • the last one must show name, surname and number of orders of a user

So I would call 3 different queries on my db:

  • the first one that loads Id, Name and Surname of all the users
  • the second one that loads Name, Surname and Premium starting from an id
  • the third one that loads Name, Surname and OrdersNumber starting from an id

The problem is when I map the result of the queries to a User object:

  • in the first case I would obtain objects with Premium=false and OrdersNumber=0
  • in the second case I would obtain an object with OrdersNumber=0
  • in the third case I would obtain an object with Premium=false

These data are not correct, they’ve simply set to their default value.
So what should I to do?

  • I can ignore the problem, and use the properties only when I know that their values have been loaded
  • I can modify Premium and OrdersNumber in order to accept null value (the problem of this solution is that maybe User objects (on domain) have always Premium and OrdersNumber data, so the class doesn’t respect domain rules.):
public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Surname { get; set; }
        public bool? Premium { get; set; }
        public int? OrdersNumber { get; set; }
    }
  • everytime I need users data, I load all the fields, even the ones I don’t kneed.
    The problem of this solution is the waste of time and memory.

Which is the best solution?

interaction design – How to work with visual designers who treat wireframes as literal graphic suggestions?

Recently I started to face quite many cases on my client projects when a visual designer on the team produces design that looks like wireframes produced by me, only colored. Perhaps, the obvious answer to my question is “don’t work with this kind of designers”. In most cases, however, the projects I’m working on are really interesting and challenging, so if I want to stay on the project I’m forced to work with whoever is on the team, so I better find the way to solve it.

I have talked to the teams explaining what wireframes are and what they are not and why applying some color to my wireframes is not a good design job. I have shown examples of excellent design jobs done based on wireframes. I have also switched from Omnigraffle to Balsamiq in order to produce mockups that look more like sketches hoping that this would force the visual designers to be more creative. It doesn’t seem to work very well.

I know what it’s like to work with designers who are able to (correctly) treat the wireframes only as guidelines for content, position, hierarchy, functionality, interactions, flow definition, etc. and do their magic to wrap it all up in a beautiful and elegant visual surface. That’s the reason the opposite cases cause so much frustration.

Has anyone faced a situation like that? If yes, what worked well and what didn’t assuming you tried to do something about it?